本篇文章小编给大家分享一下SpringBoot中的Mybatis依赖问题代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
Pom导入依赖
org.mybatis.spring.boot mybatis-spring-boot-starter 2.0.0
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