隨筆:3 文章:0 評論:32 引用:0
          BlogJava 首頁 發新隨筆
          發新文章 聯系 聚合管理

          2014年12月3日

          d1:為自定義查詢

          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;
          }
          控制臺打印的sql文如下
          (select
                      org.org_Name 
                  from
                      Fw_Org org 
                  where
                      org.id= this_.org_Id) as formula0_0_ 
          3:注意事項
          3.1:@Formula這個注解不能和javax.persistence.Transient這個注解一起用。
          3
          .2:使用@Formula的時候,在本entity中的其他注解要么全部在方法上,要么全部在變量上。
          3.3:@Formula中的sql文會直接解析到查詢中,即語法為原生sql語法。

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

          2013年3月15日

          1:準備:
              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文件和生成客戶端調用代碼: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:配置環境:
              2.1:配置java環境變量(不贅述)。
              2.1:eclipse中axis2環境配置: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,把得到的兩個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:發布axis2:
              3.1:解壓axis2-1.6.2-war.zip獲得axis2.war并把它放到tomcat解壓目錄的webapps文件夾下,啟動tomcat,瀏覽器中輸入http://localhost:8080/axis2/,出現圖3.1,說明配置成功。
          圖3.1
              3.2:用eclipse的axis2插件發布web服務。
                  3.2.1    在eclipse中new一個Dynamic Web Project,取名webserviceService。編寫一個簡單的webService服務器代碼
          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,在彈出的對話框中,找到Axis2 Service Archiver,雙擊->選擇HelloWorldService所在項目的class路徑,如圖3.2
          圖3.2
          next->選中skip WSDL,Next->什么都不填NEXT->選中Generate the service xml automatically,NEXT->
          圖3.3
          如如圖3.3填寫HelloWorldService類的全路徑,點擊load,在下面的Method表中出現sayHello說明load成功,點擊NEXT->
          圖3.4
              填寫Output file location,點擊Finish,如圖3.4。
                  3.2.2    右鍵點擊webServiceService項目,刷新。出現my_service.aar文件,如圖3.5。
          圖3.5
              把此aar文件放到%tomcat_home%\webapps\axis2\WEB-INF\services下。瀏覽器中輸入http://localhost:8080/axis2/services/HelloWorldService?wsdl,出現圖3.6,說明發布成功。
          圖3.6
          4:用eclipse的Web Service Client生成客戶端調用代碼。
              4.1:在eclipse的空白workspace處右鍵new->Other->Web services->Web Service Client,選中,點擊NEXT->出現圖4.1圖4.1
          service definition填發布好的wsdl路徑http://localhost:8080/axis2/services/HelloWorldService?wsdl,Client type默認,下面的下滑快拉到最上面,點擊Server runtime:Tomcat v6.0 Server出現圖4.2:
          圖4.2
          在Server runtime中選擇默認,Web service runtime選擇Apache Axis2,點擊Ok,返回圖4.1,點擊Client project:webServiceClient,出現圖4.3圖4.3
          在Client project的下拉列表中選擇客戶端代碼存放的項目,本例選擇webServiceClient。點擊OK,返回圖4.1,點擊NEXT,進入下一個環節,然后點擊Finish。
          ,圖4.4
          如圖4.4,在src的source folder下出現org.web.service包,下面有HelloWorldServiceCallBackHandler.java和HelloWorldServiceStub.java文件,Web App Libraries也有更新,在WebContent目錄下也出現axis2-web文件夾,以及WEB-INF等的更新。
              4.2:寫webService調用代碼。
                      在webServiceClient項目中新建一個客戶端測試文件如下:
           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提供參數
          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 }
          運行上面代碼Run As->Java Application,輸出:
          Hello,jackii
          說明調用成功。
          5:參考文檔http://wenku.baidu.com/view/12501ed7195f312b3169a54b.html
          6:服務端接收的參數為javaBean,返回list樣例:
              6.1:創建服務。新建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說明重新發布服務(圖3.4Output File Name重新起個名字)
          6.2:創建客戶端調用代碼,步奏同4。得到圖6.2所示兩個文件ListServiceStub.java和ListServiceCallbackHandler.java
          圖6.2
          創建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方式運行,輸出:
          1 id:clientTestname:ClientName
          2 
          3 id:000name:jack000
          4 
          5 id:001name:jack001
          6 
          7 id:002name:jack002
          說明調用成功。
          posted @ 2013-03-15 10:42 橴Sè單純 閱讀(57446) | 評論 (17)編輯 收藏

          2010年8月26日

          2010年8月28號19點30分,哥來了,BlogJava你好!
          java你好,哥正式進軍java世界!
          posted @ 2010-08-26 19:35 橴Sè單純 閱讀(1667) | 評論 (15)編輯 收藏
          CALENDER
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜


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

          主站蜘蛛池模板: 丰原市| 凤台县| 赣榆县| 阿坝县| 波密县| 从化市| 洪泽县| 炎陵县| 河北区| 郎溪县| 惠州市| 双江| 乌审旗| 县级市| 兴城市| 石首市| 潮安县| 遂宁市| 安龙县| 清水县| 嘉黎县| 郴州市| 桂阳县| 休宁县| 元江| 平昌县| 武夷山市| 鄂伦春自治旗| 安溪县| 富平县| 晋江市| 香格里拉县| 南乐县| 杂多县| 奇台县| 增城市| 沾益县| 博湖县| 连城县| 夏邑县| 措勤县|