通用后台管理系统(3)-测试环境是否成功

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      
     * @throws
     */
    List 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 selectAdmin() {
        AdminUserExample example = new AdminUserExample();
        List list = adminUserMapper.selectByExample(example);
        return list;
    }
}

4、设置dubbo暴露的服务接口

在backend-server-rpc中 applicationContext-service.xml 添加一条xml

5、引用dubbo服务

在backend-server-web中 applicationContext-dubbo.xml 添加一条xml

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 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
    }
]

你可能感兴趣的:(通用后台管理系统(3)-测试环境是否成功)