隨筆:3 文章:0 評(píng)論:32 引用:0
          BlogJava 首頁(yè) 發(fā)新隨筆
          發(fā)新文章 聯(lián)系 聚合管理

          2014年12月3日

          d1:為自定義查詢(xún)

          2:使用樣例

          @Formula("(select org.org_Name from Fw_Org org where org.id= org_Id)")
          public String getOrgName() {
          return orgName;
          }
          public void setOrgName(String orgName) {
          this.orgName = orgName;
          }
          控制臺(tái)打印的sql文如下
          (select
                      org.org_Name 
                  from
                      Fw_Org org 
                  where
                      org.id= this_.org_Id) as formula0_0_ 
          3:注意事項(xiàng)
          3.1:@Formula這個(gè)注解不能和javax.persistence.Transient這個(gè)注解一起用。
          3
          .2:使用@Formula的時(shí)候,在本entity中的其他注解要么全部在方法上,要么全部在變量上。
          3.3:@Formula中的sql文會(huì)直接解析到查詢(xún)中,即語(yǔ)法為原生sql語(yǔ)法。

          posted @ 2014-12-03 11:20 橴Sè單純 閱讀(985) | 評(píng)論 (0)編輯 收藏

          2013年3月15日

          1:準(zhǔn)備:
              JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-1902814.html
              eclipse:http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR2/eclipse-jee-juno-SR2-win32.zip
              tomcat:http://tomcat.apache.org/download-60.cgi
              axis2:http://axis.apache.org/axis2/java/core/download.cgi
              eclipse的官方提供的axis插件工具,可以打包aar文件和生成客戶(hù)端調(diào)用代碼:http://axis.apache.org/axis2/java/core/tools/index.html

                  其中的Service Archive Wizard - Eclipse Plug-in和Code Generator Wizard - Eclipse Plug-in
          下載完成的軟件如圖1.1

          圖1.1
          2:配置環(huán)境:
              2.1:配置java環(huán)境變量(不贅述)。
              2.1:eclipse中axis2環(huán)境配置:Window->Perferences->Web Services->Axis2 perferences->Axis2 Runtime->Axis2 Runtime location,Browse選擇解壓axis2-1.6.2-bin.zip得到的axis2-1.6.2文件目錄。如圖2.1。
                  圖2.1
              2.2:安裝插件:解壓axis2-eclipse-codegen-plugin-1.6.2.zip和axis2-eclipse-service-plugin-1.6.2.zip,把得到的兩個(gè)jar包放入eclipse目錄下的\plugins\中,重啟eclipse。
              2.3:配置tomcat:解壓apache-tomcat-6.0.36-windows-x64.zip(不贅述)。
              2.4:eclipse中tomcat配置:Window->Perferences->Server->Runtime Environments添加。
          3:發(fā)布axis2:
              3.1:解壓axis2-1.6.2-war.zip獲得axis2.war并把它放到tomcat解壓目錄的webapps文件夾下,啟動(dòng)tomcat,瀏覽器中輸入http://localhost:8080/axis2/,出現(xiàn)圖3.1,說(shuō)明配置成功。
          圖3.1
              3.2:用eclipse的axis2插件發(fā)布web服務(wù)。
                  3.2.1    在eclipse中new一個(gè)Dynamic Web Project,取名webserviceService。編寫(xiě)一個(gè)簡(jiǎn)單的webService服務(wù)器代碼
          1 package org.web.service;
          2 
          3 public class HelloWorldService {
          4     public String sayHello(String name){
          5         return "Hello," + name;
          6     }
          7 }
          8 
                  3.2.2    在eclipse的空白workspace處,右鍵new->Other,在彈出的對(duì)話(huà)框中,找到Axis2 Service Archiver,雙擊->選擇HelloWorldService所在項(xiàng)目的class路徑,如圖3.2
          圖3.2
          next->選中skip WSDL,Next->什么都不填NEXT->選中Generate the service xml automatically,NEXT->
          圖3.3
          如如圖3.3填寫(xiě)HelloWorldService類(lèi)的全路徑,點(diǎn)擊load,在下面的Method表中出現(xiàn)sayHello說(shuō)明load成功,點(diǎn)擊NEXT->
          圖3.4
              填寫(xiě)Output file location,點(diǎn)擊Finish,如圖3.4。
                  3.2.2    右鍵點(diǎn)擊webServiceService項(xiàng)目,刷新。出現(xiàn)my_service.aar文件,如圖3.5。
          圖3.5
              把此aar文件放到%tomcat_home%\webapps\axis2\WEB-INF\services下。瀏覽器中輸入http://localhost:8080/axis2/services/HelloWorldService?wsdl,出現(xiàn)圖3.6,說(shuō)明發(fā)布成功。
          圖3.6
          4:用eclipse的Web Service Client生成客戶(hù)端調(diào)用代碼。
              4.1:在eclipse的空白workspace處右鍵new->Other->Web services->Web Service Client,選中,點(diǎn)擊NEXT->出現(xiàn)圖4.1圖4.1
          service definition填發(fā)布好的wsdl路徑http://localhost:8080/axis2/services/HelloWorldService?wsdl,Client type默認(rèn),下面的下滑快拉到最上面,點(diǎn)擊Server runtime:Tomcat v6.0 Server出現(xiàn)圖4.2:
          圖4.2
          在Server runtime中選擇默認(rèn),Web service runtime選擇Apache Axis2,點(diǎn)擊Ok,返回圖4.1,點(diǎn)擊Client project:webServiceClient,出現(xiàn)圖4.3圖4.3
          在Client project的下拉列表中選擇客戶(hù)端代碼存放的項(xiàng)目,本例選擇webServiceClient。點(diǎn)擊OK,返回圖4.1,點(diǎn)擊NEXT,進(jìn)入下一個(gè)環(huán)節(jié),然后點(diǎn)擊Finish。
          ,圖4.4
          如圖4.4,在src的source folder下出現(xiàn)org.web.service包,下面有HelloWorldServiceCallBackHandler.java和HelloWorldServiceStub.java文件,Web App Libraries也有更新,在WebContent目錄下也出現(xiàn)axis2-web文件夾,以及WEB-INF等的更新。
              4.2:寫(xiě)webService調(diào)用代碼。
                      在webServiceClient項(xiàng)目中新建一個(gè)客戶(hù)端測(cè)試文件如下:
           1 package org.web.client;
           2 
           3 import java.rmi.RemoteException;
           4 
           5 import org.web.service.HelloWorldServiceStub;
           6 import org.web.service.HelloWorldServiceStub.SayHelloResponse;
           7 
           8 public class HelloWorldClient {
           9 
          10     /**
          11      * @param args
          12      * @throws RemoteException 
          13      */
          14     public static void main(String[] args) throws RemoteException {
          15         String target = "http://localhost:8080/axis2/services/HelloWorldService";
          16         HelloWorldServiceStub stub = new HelloWorldServiceStub(target);
          17         // sayHello 為webService提供參數(shù)
          18         HelloWorldServiceStub.SayHello sayHello = new HelloWorldServiceStub.SayHello();
          19         sayHello.setName("jackii");
          20         SayHelloResponse eur = stub.sayHello(sayHello);
          21         String returnVal = eur.get_return();
          22         System.out.println(returnVal);
          23     }
          24 
          25 }
          運(yùn)行上面代碼Run As->Java Application,輸出:
          Hello,jackii
          說(shuō)明調(diào)用成功。
          5:參考文檔http://wenku.baidu.com/view/12501ed7195f312b3169a54b.html
          6:服務(wù)端接收的參數(shù)為javaBean,返回list樣例:
              6.1:創(chuàng)建服務(wù)。新建User.java
           1 package org.web.service;
           2 
           3 public class User {
           4     private String id;
           5     private String name;
           6     public String getId() {
           7         return id;
           8     }
           9     public void setId(String id) {
          10         this.id = id;
          11     }
          12     public String getName() {
          13         return name;
          14     }
          15     public void setName(String name) {
          16         this.name = name;
          17     }
          18 }
          19 
          ListService.java
           1 package org.web.service;
           2 
           3 import java.util.ArrayList;
           4 import java.util.List;
           5 
           6 public class ListService {
           7     public List<User> getUserList(User user){
           8         List<User> returnList = new ArrayList<User>();
           9         returnList.add(user);
          10         for(int i=0;i<3;i++){
          11             User user1 = new User();
          12             user1.setId("00"+i);
          13             user1.setName("jack00"+i);
          14             returnList.add(user1);
          15         }
          16         return returnList;
          17     }
          18 }
          文件目錄如圖6.1:
          圖6.1
          按照3.2說(shuō)明重新發(fā)布服務(wù)(圖3.4Output File Name重新起個(gè)名字)
          6.2:創(chuàng)建客戶(hù)端調(diào)用代碼,步奏同4。得到圖6.2所示兩個(gè)文件ListServiceStub.java和ListServiceCallbackHandler.java
          圖6.2
          創(chuàng)建ListServiceClient.java
           1 package org.web.client;
           2 
           3 import java.rmi.RemoteException;
           4 
           5 import org.web.service.ListServiceStub;
           6 import org.web.service.ListServiceStub.GetUserListResponse;
           7 import org.web.service.ListServiceStub.User;
           8 
           9 public class ListServiceClient {
          10 
          11     /**
          12      * @param args
          13      * @throws RemoteException 
          14      */
          15     public static void main(String[] args) throws RemoteException {
          16         String target = "http://localhost:8080/axis2/services/ListService";
          17         ListServiceStub stub = new ListServiceStub(target);
          18         ListServiceStub.GetUserList getUserList0 = new ListServiceStub.GetUserList();
          19         User user = new User();
          20         user.setId("clientTest");
          21         user.setName("ClientName");
          22         getUserList0.setUser(user);
          23         GetUserListResponse eur = stub.getUserList(getUserList0);
          24         User[] userArray = eur.get_return();
          25         for(int i=0;i<userArray.length;i++){
          26             System.out.println("id:"+userArray[i].getId()+"name:"+userArray[i].getName()+"\n");
          27         }
          28     }
          29 }
          以java application方式運(yùn)行,輸出:
          1 id:clientTestname:ClientName
          2 
          3 id:000name:jack000
          4 
          5 id:001name:jack001
          6 
          7 id:002name:jack002
          說(shuō)明調(diào)用成功。
          posted @ 2013-03-15 10:42 橴Sè單純 閱讀(57458) | 評(píng)論 (17)編輯 收藏

          2010年8月26日

          2010年8月28號(hào)19點(diǎn)30分,哥來(lái)了,BlogJava你好!
          java你好,哥正式進(jìn)軍java世界!
          posted @ 2010-08-26 19:35 橴Sè單純 閱讀(1675) | 評(píng)論 (15)編輯 收藏
          CALENDER
          <2025年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類(lèi)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜


          Powered By: 博客園
          模板提供滬江博客

          主站蜘蛛池模板: 和顺县| 碌曲县| 长阳| 普宁市| 林西县| 宝山区| 介休市| 崇礼县| 惠水县| 怀远县| 邹平县| 米林县| 苗栗县| 福建省| 恩平市| 贡嘎县| 司法| 准格尔旗| 抚顺市| 曲沃县| 贵德县| 象州县| 宁陵县| 马边| 嘉鱼县| 闸北区| 礼泉县| 漳州市| 敦煌市| 霍邱县| 施秉县| 巴林右旗| 南雄市| 武山县| 松滋市| 平山县| 阿荣旗| 通州市| 滨海县| 灵山县| 合川市|