1、生成mapper pojo
使用 generatorSqlmapCustom生成
2、编写接口类
package com.sundablog.service;
import java.util.List;
import com.sundablog.pojo.AdminUser;
public interface TestService {
/**
* 查询全部管理员
* @Title: selectAdmin
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @return
* @return: List<AdminUser>
* @throws
*/
List<AdminUser> selectAdmin();
}
3、编写接口类
package com.sundablog.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sundablog.mapper.AdminUserMapper;
import com.sundablog.pojo.AdminUser;
import com.sundablog.pojo.AdminUserExample;
import com.sundablog.service.TestService;
@Service
public class TestServiceImpl implements TestService {
@Autowired
private AdminUserMapper adminUserMapper;
@Override
public List<AdminUser> selectAdmin() {
AdminUserExample example = new AdminUserExample();
List<AdminUser> list = adminUserMapper.selectByExample(example);
return list;
}
}
4、设置dubbo暴露的服务接口
在backend-server-rpc中 applicationContext-service.xml 添加一条xml
<dubbo:service interface="com.sundablog.service.TestService" ref="testServiceImpl" version="1.0.0" />
5、引用dubbo服务
在backend-server-web中 applicationContext-dubbo.xml 添加一条xml
<dubbo:reference interface="com.sundablog.service.TestService" id="testService" version="1.0.0" />
6、编写控制器类
package com.sundablog.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sundablog.pojo.AdminUser;
import com.sundablog.service.TestService;
@Controller
public class TestController {
@Autowired
public TestService testService;
@RequestMapping("/test")
@ResponseBody
public List<AdminUser> text(){
return testService.selectAdmin();
}
}
7.运行
先把其他maven 工程使用install 打车jar包 使用命令 clean tomcat7:run 运行
7.1运行结果
[
{
"userId": 3,
"username": "admin",
"password": "123",
"salt": "123",
"realname": "12",
"avatar": "12",
"phone": "12",
"email": "12312",
"sex": 1,
"locked": 1,
"ctime": 1521023965000
}
]