zoukankan      html  css  js  c++  java
  • 通用后台管理系统(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<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
        }
    ]
    
  • 相关阅读:
    什么是抽象类?什么是抽象方法,接口和抽象类有什么区别?
    IDEA中使用maven run clear 和tomcat:run等操作记录。
    IDEA maven项目解决不能创建package 和 java class问题,文件夹蓝色
    使用IDEA创建一个maven项目详细步骤
    单元测试运行报错org.junit.runner.Description.getClassName()Ljava/lang/String
    qq互联
    php 生成文字图片
    Zen Coding
    html 超出隐藏
    php获取网站ico
  • 原文地址:https://www.cnblogs.com/sundaboke/p/8616776.html
Copyright © 2011-2022 走看看