springboot整合mybatis

创建user表:

CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(50) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

并手动添加一条信息

首先创建一个springboot项目,创建完成后需要在pom.xml文件中添加如下图中红色的部分的代码,添加mysql和我们需要用到的注解的jar包,更新maven后,会把这些jar下载到项目中使用。



项目目录结构如下:

  


在entity文件下创建实体类User.java


在controller文件下创建UserController.java



@RestController是两个注解的合并,作用是表面这个类是Controller层并向请求返回数据,不能返回视图。
@RequestMapping("/user")为请求路径,
@Autowired 注入userService
@GetMapping("/getList") 访问当前方法需要使用get请求,访问名称为getList

创建IUserService接口


创建UserServiceImpl

  


创建UserMapper

  


创建UserMapper.xml


最后配置mysql和xml文件

application.properties文件是springboot的配置文件,

 


启动项目,访问http://127.0.0.1:8080/user/getlist

 





原文地址:https://www.cnblogs.com/yinduang/p/10021185.html