学习webservice之cxf(4):cxf处理javabean以及复合类型

@WebService
public class HelloWorldImpl implements HelloWorld{

    public String say(String str) {
        return "Hello:"+str;
    }

    public List<Role> getRoleByUser(User user) {
        List<Role> roleList=new ArrayList<Role>();
        // 模拟  直接写死
        if(user!=null){
            if(user.getUserName().equals("java1234") && user.getPassword().equals("123456")){
                roleList.add(new Role(1,"技术总监"));
                roleList.add(new Role(2,"架构师"));
            }else if(user.getUserName().equals("jack") && user.getPassword().equals("123456")){
                roleList.add(new Role(3,"程序员"));
            }
            return roleList;
        }else{
            return null;
        }
    }

}

 

package com.rg2.webservice;

import java.util.List;

public class Client {

    public static void main(String[] args) {
        HelloWorldService service = new HelloWorldService();
        HelloWorld helloWorldPort = service.getHelloWorldPort();
//        System.out.println(helloWorldPort.say("rg2_cxf"));
        
        User user = new User();
        user.setUserName("rg2");
        user.setPassword("123456");
        List<Role> roleList = helloWorldPort.getRoleByUser(user);
        for (Role role : roleList) {
            System.out.println(role.getId()+","+role.getRoleName());
        }
    }

}

 

posted @ 2018-07-05 23:24  十黎九夏  阅读(202)  评论(0编辑  收藏  举报