SpringBoot中的Mybatis依赖问题怎么解决
导读:本文共2392.5字符,通常情况下阅读需要8分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: Pom导入依赖<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.0</version>... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。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=utf8username:rootpassword:123driver-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> <!--核心springbootstarter,包括自动配置支持,日志和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>
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
SpringBoot中的Mybatis依赖问题怎么解决的详细内容,希望对您有所帮助,信息来源于网络。