springboot微服务搭建(一):整合mybatis配置(第一种方式)
2017-11-10 15:54
936 查看
现在看网上springboot集成mybatis有两种方式:第一种是使用maven的mybatis的依赖,填写配置文件;第二种是采用spring-mybatis的配置。
第一种,在已有的springboot项目的pom文件中加入
然后在application.properties中添加
springboot会按照spring.datasource自动去匹配各种属性。mybatis.typeAliasesPackage扫描实体类位置,mybatis.mapperLocations扫描mybatis的xml文件。
然后在启动文件中加入
用于扫描mybatis的接口。在mybatis的mapper文件加入@Mapper注解也可以,但是会增加工作量。
至此,第一种方式配置完毕。properties文件中还可以加入许多其他的配置,相信百度可以找到。其他的配置也没研究过。
第一种,在已有的springboot项目的pom文件中加入
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency>
然后在application.properties中添加
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test spring.datasource.username=root spring.datasource.password= spring.datasource.driver-class-name=com.mysql.jdbc.Driver mybatis.typeAliasesPackage=com.main.db.model mybatis.mapperLocations=classpath:com/main/db/**/*Mapper.xml
springboot会按照spring.datasource自动去匹配各种属性。mybatis.typeAliasesPackage扫描实体类位置,mybatis.mapperLocations扫描mybatis的xml文件。
然后在启动文件中加入
@MapperScan("com.main.db.dao")//扫描dao
用于扫描mybatis的接口。在mybatis的mapper文件加入@Mapper注解也可以,但是会增加工作量。
至此,第一种方式配置完毕。properties文件中还可以加入许多其他的配置,相信百度可以找到。其他的配置也没研究过。
相关文章推荐
- SpringCloud SpringBoot mybatis 分布式微服务(二十)Spring Boot 自定义配置文件
- Spring boot + mysql +mybatis 配置整合实例
- Spring Cloud Spring Boot mybatis分布式微服务云架构(三十三)注解配置与EhCache使用(1)
- Spring+SpringMVC+MyBatis整合配置文件的搭建
- SpringBoot整合MyBatis(包含热部署及其JSP配置详解)
- Spring Boot整合oauth2.0搭建统一授权服务(密码模式)
- spring整合mybatis,springMVC的0配置文件方式
- (十)整合spring cloud云服务架构 - commonservice-config配置服务搭建
- SpringCloud SpringBoot mybatis 分布式微服务(十五)Spring Boot中使用MyBatis注解配置详解
- Springboot整合Mybatis的CallSettersOnNulls配置问题
- 第二章:Dubbo整合maven+spring+springmvc+mybatis之服务提供者搭建
- IDEA上搭建maven项目整合springboot+mybatis+shiro
- Spring Cloud Spring Boot mybatis分布式微服务云架构(二十六)使用MyBatis注解配置详解(1)
- Spring boot入门五 spring mvc spring boot mybatis配置整合
- 使用myeclipse搭建SpringBoot框架,整合thymeleaf模板和mybatis
- Spring boot整合mybatis实现Restful服务demo
- javaWeb项目SpringMVC3.2.1与Mybatis3.0.4整合实例(Mybaits-spring配置文件的几种方式)之一SqlSessionDaoSupport方式
- springboot 整合 Mybatis (纯配置文件)
- springboot整合mybatis,动态数据源配置
- springboot搭建web(整合mybatis)(四)