第五章 springboot + mybatis
2016-04-03 16:06
477 查看
springboot集成了springJDBC与JPA,但是没有集成mybatis,所以想要使用mybatis就要自己去集成。集成方式相当简单。
1、项目结构
View Code
测试:
进入项目的pom.xml文件所在目录,执行"mvn spring-boot:run"(这是最推荐的spring-boot的运行方式),另外一种在主类上右击-->"run as"-->"java application"不常用
参考自:
http://www.111cn.net/jsp/Java/93604.htm :springboot+mybatis+多数据源
http://blog.csdn.net/xiaoyu411502/article/details/48164311:springboot+mybatis+读写分离(其实读写分离就是两个数据源对两个库进行操作)
1、项目结构
package com.xxx.firstboot.web; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.xxx.firstboot.domain.User; import com.xxx.firstboot.service.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; @RestController @RequestMapping("/user") @Api("userController相关api") public class UserController { @Autowired private UserService userService; @ApiOperation("添加用户") @ApiImplicitParams({ @ApiImplicitParam(paramType="query",name="username",dataType="String",required=true,value="用户的姓名",defaultValue="zhaojigang"), @ApiImplicitParam(paramType="query",name="password",dataType="String",required=true,value="用户的密码",defaultValue="wangna") }) @ApiResponses({ @ApiResponse(code=400,message="请求参数没填好"), @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对") }) @RequestMapping(value="/addUser",method=RequestMethod.POST) public boolean addUser(@RequestParam("username") String username, @RequestParam("password") String password) { return userService.addUser(username,password); } @ApiOperation("添加用户且返回已经设置了主键的user实例") @ApiImplicitParams({ @ApiImplicitParam(paramType="query",name="username",dataType="String",required=true,value="用户的姓名",defaultValue="zhaojigang"), @ApiImplicitParam(paramType="query",name="password",dataType="String",required=true,value="用户的密码",defaultValue="wangna") }) @ApiResponses({ @ApiResponse(code=400,message="请求参数没填好"), @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对") }) @RequestMapping(value="/addUserWithBackId",method=RequestMethod.POST) public User addUserWithBackId(@RequestParam("username") String username, @RequestParam("password") String password) { return userService.addUserWithBackId(username, password); } }
View Code
测试:
进入项目的pom.xml文件所在目录,执行"mvn spring-boot:run"(这是最推荐的spring-boot的运行方式),另外一种在主类上右击-->"run as"-->"java application"不常用
参考自:
http://www.111cn.net/jsp/Java/93604.htm :springboot+mybatis+多数据源
http://blog.csdn.net/xiaoyu411502/article/details/48164311:springboot+mybatis+读写分离(其实读写分离就是两个数据源对两个库进行操作)
相关文章推荐
- J2EE 日志错误
- eclipse中英文版转换(前提:有中文包)
- get√ Java
- JavaWeb - XML
- Java并发编程系列之九:AQS
- javaweb学习之servlet
- JAVA虚拟机-JMM内存模型(六)
- Java常见异常总结
- 被事务代理的spring service 使用注解方式发布Dubbo服务
- Java I/O 模型的演进
- Struts2入门了解1
- Java理解堆栈区
- Java作业。。。
- AQS(4):condition
- AQS(3):release
- 如何利用线程的生命周期使小球撞墙弹回
- spring MVC配置form支持PUT和DELETE方法
- Java 时间格式转换
- AQS(1):引言
- Java并发:线程间同步机制:条件队列和同步工具类