SpringBoot整合MyBatis
2017-07-18 15:58
417 查看
一、创建数据库spring_boot,并增加表:
二、使用Intellij Idea新建一个SpringBoot工程,起始依赖选择mysql、mybatis,其它按需选择
三、在配置文件 application.yml 中增加数据库信息:
四、使用Mybatis Generator生成和数据表对应的实体类和mapper文件
五、将文件复制到相应位置,结构图:
六、在配置文件 application.yml 中增加实体类的包名和mapper.xml文件位置:
七、在工程启动类Application中增加注解 @MapperScan("com.zhqing.mapper"), 否则在每个mapper类中都需要增加
八、通过 自动注入的方式调用接口方法
二、使用Intellij Idea新建一个SpringBoot工程,起始依赖选择mysql、mybatis,其它按需选择
三、在配置文件 application.yml 中增加数据库信息:
spring: datasource: url: jdbc:mysql://localhost:3306/spring_boot username: root password: 320121
四、使用Mybatis Generator生成和数据表对应的实体类和mapper文件
五、将文件复制到相应位置,结构图:
六、在配置文件 application.yml 中增加实体类的包名和mapper.xml文件位置:
mybatis: type-aliases-package: com.zhqing.entity mapper-locations: classpath:mapper/*.xml
七、在工程启动类Application中增加注解 @MapperScan("com.zhqing.mapper"), 否则在每个mapper类中都需要增加
@SpringBootApplication @MapperScan("com.zhqing.mapper") public class SpringbootApplication { public static void main(String[] args) { SpringApplication.run(SpringbootApplication.class, args); } }
八、通过 自动注入的方式调用接口方法
@Autowired private UserMapper userMapper;
相关文章推荐
- SpringBoot整合Mybatis出现的错误
- SpringBoot + Mybatis plus 实现多数据源整合
- Spring Boot+Mybatis+MySql 完整整合教程
- SpringBoot构建微服务实战 之 整合Mybatis(一)
- [Spring Boot实战系列] - No.3 Spring boot 整合Mybatis
- springboot整合mybatis
- Spring Boot---(8)SpringBoot整合mybatis
- spring-boot 整合mybatis 配置 可以发布到tomcat中运行
- springboot整合mybatis
- springboot+shiro+mybatis整合发现部分功能事务没有被spring管理
- spring boot 整合MyBatis
- springboot学习笔记-2 一些常用的配置以及整合mybatis
- springboot整合Mybatis
- [四]Spring Boot 整合Mybatis
- Spring boot 整合mybatis
- 一头扎进springboot之整合mybatis
- 二十、Spring Boot整合MyBatis(下)
- spring boot 整合 mybatis
- SpringBoot整合Mybatis之进门篇
- SpringBoot 快速整合MyBatis