[ Spring MVC ] 整合Mybatis开发

Spring MVC 整合Mybatis开发

maven

  org.mybatis
  mybatis-spring
  1.3.0

mybatis配置和数据库配置
sqlMapConfig.xml (含分页插件)




    
    
    
    
    
    
    
    
    
    
    
    
    



    
    
        
        
        
        
        
        
        
        
    





spring-dao.xml 游戏数据配置


   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/tx
   http://www.springframework.org/schema/tx/spring-tx.xsd">

Spring-Database配置



    
    
    
    
    
    
    
    
    
     60 
    
    5
    
    0
    
    60
    
    30
    
    true
    
    false




    
    
    
  
    
    




    
    




    



    
        
        
        
        
        
        
        
    


generatorConfig.xml
pojo、mapper.xml、dao 逆向生成游戏插件


    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">





    
        
        
        
    

    
    
    
    
    
        
    
    
    
        
        
        
        
    
    
    
        
    
    
    
        
    

    

maven


    org.mybatis.generator
    mybatis-generator-maven-plugin
    1.3.5
    
        true
        true
    




接口定义和实现类(供Controller)
接口定义

/**

  • 表单相关
    *
  • @author YF-XIACHAOYANG
  • @date 2017/12/21 11:38
    */

public interface FormRestServices {

/**
 * 表单基础接口
 */
interface BASE {
    RespMapJson selectTest();
}

}

服务层实现类

/**

  • 表单基础服务
  • @author YF-XIACHAOYANG
  • @date 2018/3/15 16:12
    */

@Service
public class Formwww.cungun.comBaseServiceImpl implements FormRestServices.BASE {

@Resource
private FormTemplateMapper formTemplateMapper;

@Override
public RespMapJson selectTest() {
    FormTemplate form = formTemplateMapper.selectByPrimaryKey(Long.valueOf(1));
    System.out.println(form.getContent());
    return new RespMapJson().setData(form);
}

}

FormTemplateMapper 为 mydsatis 逆向工程插件生成

Controller调用

/**

  • 任务查询控制器
  • @author YF-XIACHAOYANG
  • @date 2017/12/20 16:51
    */

@Api(value = "form", description = "工作流表单管理")
@RestController
@RequestMapping("/data/form/")
public class FormRestController {

@Autowired
private FormRestServices.BASE formBaseService;

/**
 * testMybatis
 *
 * @return
 */
@RequestMapping(value = "/testMybatis", method = RequestMethod.POST)
public RespMapJson testMybatis()  {
   return formBaseService.selectTest();
}

}

至此,可以开始基于mybatis的开发工作了!

你可能感兴趣的:([ Spring MVC ] 整合Mybatis开发)