SpringBoot中的Mybatis依赖问题怎么解决


本篇内容主要讲解“SpringBoot中的Mybatis依赖问题怎么解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“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=utf8username:rootpassword:123driver-class-name:&nbsp.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&gt.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&gtmons-httpclient</groupId><artifactId&gtmons-httpclient</artifactId><version>3.1</version><!--pagehelper--><!--<dependency><groupId&gt.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId></dependency>--><groupId&gt.github.pagehelper</groupId><artifactId>pagehelper</artifactId><version>4.1.6</version></dependency></dependencies>

到此,相信大家对“SpringBoot中的Mybatis依赖问题怎么解决”有了更深的了解,不妨来实际操作一番吧!这里是主机评测网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


上一篇:es6解构的含义是什么

下一篇:C语言中main函数与命令行参数实例分析


Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器