CXF-02: 使用CXF处理JavaBean式的复合类型和List集合类型
Cat.java:
package com.war3.ws.domain; public class Cat { private Integer id;
private String name;
private String color; public Cat() {
super();
} public Cat(Integer id, String name, String color) {
super();
this.id = id;
this.name = name;
this.color = color;
} public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
} }
User.java:
package com.war3.ws.domain; public class User { private Integer id;
private String name;
private String pass;
private String address; public User() {
super();
} public User(Integer id, String name, String pass, String address) {
super();
this.id = id;
this.name = name;
this.pass = pass;
this.address = address;
} public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((pass == null) ? 0 : pass.hashCode());
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (pass == null) {
if (other.pass != null)
return false;
} else if (!pass.equals(other.pass))
return false;
return true;
} }
UserService.java:
package com.war3.service; import java.util.List; import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; public interface UserService { List<Cat> getCatsByUser(User user);
}
UserServiceImpl.java:
package com.war3.service.impl; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.war3.service.UserService;
import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; public class UserServiceImpl implements UserService { static Map<User,List<Cat>> catDb = new HashMap<User,List<Cat>>(); static{
List<Cat> catList1 = new ArrayList<Cat>();
catList1.add(new Cat(1,"加菲猫","橙色"));
catList1.add(new Cat(2,"机器猫","蓝色"));
catDb.put(new User(1,"孙悟空","1111","花果山"), catList1); List<Cat> catList2 = new ArrayList<Cat>();
catList2.add(new Cat(3,"熊猫","黑白色"));
catList2.add(new Cat(4,"kitty","白色"));
catDb.put(new User(2,"猪八戒","2222","高老庄"), catList2);
}
@Override
public List<Cat> getCatsByUser(User user) {
return catDb.get(user);
} }
HelloWorld.java:
package com.war3.ws; import java.util.List; import javax.jws.WebService; import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; @WebService
public interface HelloWorld { List<Cat> getCatsByUser(User user);
String sayHi(String name);
}
HelloWorldWS.java:
package com.war3.ws.impl; import java.util.List; import javax.jws.WebService; import com.war3.service.UserService;
import com.war3.service.impl.UserServiceImpl;
import com.war3.ws.HelloWorld;
import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; @WebService(endpointInterface="com.war3.ws.HelloWorld")
public class HelloWorldWS implements HelloWorld{ @Override
public List<Cat> getCatsByUser(User user) {
UserService us = new UserServiceImpl();
return us.getCatsByUser(user);
} @Override
public String sayHi(String name) {
return "welcome to the google"+name;
} }
ServerMain.java:
package com.war3.ws.server; import javax.xml.ws.Endpoint; import com.war3.ws.HelloWorld;
import com.war3.ws.impl.HelloWorldWS; public class ServerMain { public static void main(String[] args) {
HelloWorld hw = new HelloWorldWS();
Endpoint.publish("http://localhost:8080/hello", hw);
System.out.println("WebService暴露服务成功!");
}
}
运行主类,暴露服务成功!
我们写一个测试类ClientMain.java:
package com.war3.ws.client; import java.util.List; import com.war3.ws.Cat;
import com.war3.ws.HelloWorld;
import com.war3.ws.User;
import com.war3.ws.impl.HelloWorldWSService; public class ClientMain { public static void main(String[] args) {
HelloWorldWSService factory = new HelloWorldWSService();
HelloWorld hw = factory.getHelloWorldWSPort();
System.out.println(hw.sayHi("tom")); User user = new User();
user.setName("孙悟空");
user.setPass("1111");
List<Cat> catList = hw.getCatsByUser(user);
for(Cat cat:catList){
System.out.println(cat.getName()+","+cat.getColor());
}
}
}
CXF-02: 使用CXF处理JavaBean式的复合类型和List集合类型的更多相关文章
- 关于很简单的设计模式,ui-dao-database,以及JavaBean和util工具类
关于很简单的设计模式,ui-dao-database,以及JavaBean和util工具类 24. 三 / J2EE / 没有评论 简单的j2ee设计模式, UI通过DAO层访问数据库或者xml文 ...
- 1067: spark.components:NavigatorContent 类型值的隐式强制指令的目标是非相关类型 String
1.错误描写叙述 此行的多个标记: -workId -1067: spark.components:NavigatorContent 类型值的隐式强制指令的目标是非相关类型 String. 2.错误原 ...
- scala中隐式转换之隐式转换调用类中本不存在的方法
/** * Created by root * Description : 隐式转换调用类中本不存在的方法 */ class Person(name : String){ def getPersonN ...
- javabean(实体类)转Map类型
javabean(实体类)转Map类型 从网上"風亦飞"的导出EXCEL的源代码提取出来的.认为非常好用.分享一下给大家,主要看beanToMap方法就OK了 /*以下是从poi导 ...
- 设计模式——懒汉式单例类PK饿汉式单例类
前言 我们都知道生活中好多小软件,有的支持多IP在线,有的仅仅局限于单个IP在线.为什么这样设计,在软件开发阶段就是,有需求就是发展.这就是软件开发的一个设计模式--懒汉式单例类和饿汉式单例类. 内容 ...
- 解决.Net MVC 中出现 非介入式客户端验证规则中的验证类型名称必须唯一。下列验证类型出现重复: required 的bug
最近在开动科技创新作品的开发,出现了一个让人很烦恼的错误,每次从浏览页跳转到编辑页时就会出现一下错误 非介入式客户端验证规则中的验证类型名称必须唯一.下列验证类型出现重复: required 上一下出 ...
- CXF学习(4) 处理无法自动转换的复合数据类型
只贴出服务端代码 1.Service接口类 package com.test.hello; import java.util.Map; import javax.jws.WebService; imp ...
- (二)CXF之用CXF官方工具生成客户端Client
一.CXF工具的下载与使用 登录CXF官网:http://cxf.apache.org/download.html 下载,本系列使用的是3.1.5版本: 添加path环境变量 二.案例 2.1 发布w ...
- css笔记02:选择器(标签式和类)
body { margin:; padding:; background:#000 url('images/backgrounds/star.png') no-repeat fixed; font: ...
随机推荐
- Dijkstra and Floyd算法
Dijkstra算法 算法思想:设G=(V,E)是一个带权有向图,把图中顶点集合V分成两组,第一组为已求出最短路径的顶点集合(用S表示,初始时S中只有一个源点,以后每求得一条最短路径 , 就将加入到集 ...
- linux iptables扩展,脚本防火墙
netfileter:防火墙内核态ip tables:防火墙用户态(管理防火墙规则) iptables的表和链表包括不同的链,链包括大量的规则4个表: raw,mangle,nat,filter5种链 ...
- JVM 指令
1.Demo 2.Class 文件说明 2.1 Class文件结构 2.2 jvm type, method signature 2.3 泛型表示 3.方法说明 3.1 方法结构 3.1.1 Thre ...
- YPbPr 和 YCbCr的区别 .
这几天在做分量视频输入,涉及分量视频表示,接触到YPbPr和YCbCr的概念,发现不光自己的项目上,对这两个概念错乱,就是网上也充斥着大量错误的说法. 分量接口有两种名称YPbPr和YCbCr,这是两 ...
- C#超级实用的一种类型—匿名类型
顾名思义 匿名类型就是没有名字的类型.当一个新的匿名对象定义与前面已经存在的类型定义的内部变量类型相同时,编译器就会只生成一个类定义,而不是各一个.匿名类型对象中仍然可以再包含匿名对象. 在C#3.0 ...
- Linux显示按文件大小降序排列
Linux显示按文件大小降序排列 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ls -ls 总用量 56 12 -rw-r--r-- 1 youhaidon ...
- java 单例模式-饿懒汉模式
单例-饿汉模式 1.将构造方法私有化,不允许外部直接创建对象 private Singleton(){}2.自己在类的内部创建一个唯一实例 private static Singleton insta ...
- iOS - Core Animation 核心动画的使用
1.简单使用示例 1.1 时钟 QClockView.h @interface QClockView : UIView /// 创建时钟界面 + (instancetype)q_clockViewWi ...
- 反射(C#编程)
反射提供了封装程序集.模块和类型的对象(Type 类型).可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性.如果代码中使用了属性,可以利用反射对 ...
- UltraEdit 脚本 实现查找替换
UltraEdit中,要实现,脚本查找替换功能,按照下文中的做法稍作修改, 现象很奇怪,有时可以进行查找替换有时不能. http://blog.csdn.net/neareast/article/de ...