SpringBoot中的Mybatis依赖问题
Pom导入依赖
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency>
application.yml
#配置数据源,yml格式 spring: datasource: url: jdbc:mysql://127.0.0.1:3306/dianping?useUnicode=true&characterEncoding=utf8 username: root password: 123 driver-class-name: com.mysql.jdbc.Driver #指定mybatis映射文件的地址 mybatis: mapper-locations: classpath:mapper/*.xml
项目结构
mybatis默认是属性名和数据库字段名一一对应的,即
数据库表列:user_name
实体类属性:user_name
但是java中一般使用驼峰命名
数据库表列:user_name
实体类属性:userName
在Springboot中,可以通过设置map-underscore-to-camel-case属性为true来开启驼峰功能。
application.properties中:
mybatis: configuration: map-underscore-to-camel-case: true
补充:下面再看下spring boot集成mybatis需要的相关依赖
<dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- springboot对面向切面编程的支持,包括spring-aop和aspectj --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> <!-- 通过spring-rabbit来支持AMQP协议 --> <artifactId>spring-boot-starter-amqp</artifactId> <!-- 对全栈web开发的支持,包括tomcat和spring-webmvc --> <artifactId>spring-boot-starter-web</artifactId> <!-- TODO 发布生产的时候需要将此段放开 --> <!-- <exclusions> --> <!-- <exclusion> --> <!-- <groupId>org.springframework.boot</groupId> --> <!-- <artifactId>spring-boot-starter-tomcat</artifactId> --> <!-- </exclusion> --> <!-- </exclusions> --> <!-- 支持常规的测试依赖,包括junit,hamcrest.mockito以及spring-test --> <artifactId>spring-boot-starter-test</artifactId> <!-- 生产准备的特征,用于帮你监控和管理应用 --> <artifactId>spring-boot-starter-actuator</artifactId> <!--核心spring boot starter,包括自动配置支持,日志和YAML --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>spring-boot-starter</artifactId> <!--对jdbc数据库的支持 --> <artifactId>spring-boot-starter-jdbc</artifactId> <!--对spring-security的支持 --> <artifactId>spring-boot-starter-security</artifactId> <!--对spring-redis的支持 ,支持Redis键值存储数据库--> <artifactId>spring-boot-starter-redis</artifactId> <!-- mybatis --> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> <!-- MYSQL --> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.30</version> <artifactId>druid</artifactId> <version>1.0.24</version> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>5.3.1.Final</version> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> <!--pagehelper --> <!-- <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> </dependency> --> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.6</version> </dependency> </dependencies>
到此这篇关于SpringBoot中的Mybatis依赖问题的文章就介绍到这了,更多相关SpringBoot Mybatis依赖内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!
赞 (0)