ityouknow / blog-comments

15 stars 0 forks source link

Spring Boot(六):如何优雅的使用 Mybatis - 纯洁的微笑博客 #258

Open ityouknow opened 5 years ago

ityouknow commented 5 years ago

http://www.ityouknow.com/springboot/2016/11/06/spring-boot-mybatis.html

这两天启动了一个新项目因为项目组成员一直都使用的是 Mybatis,虽然个人比较喜欢 Jpa 这种极简的模式,但是为了项目保持统一性技术选型还是定了 Mybatis 。到网上找了一下关于 Spring Boot 和 Mybatis 组合的相关资料,各种各样的形式都有,看的人心累,结合了 Mybatis 的官方 Demo 和文档终于找到了最简的两种模式,花了一天时间总结后分享出来。

lwcompany commented 5 years ago

极简 xml 版本,

qiangzai201611 commented 5 years ago

springboot开启mybaties的驼峰转化,采用配置方式,进行启用application.properties增加mybatis.configuration.map-underscore-to-camel-case=true 启用失败,报错Property 'configuration' and 'configLocation' can not specified with together 改用其他方式进行配置,mybatis-config.xml增加配置 settings setting name="mapUnderscoreToCamelCase" value="true settings 驼峰转化成功,需要注意 settings 必须在typeAliases之上,请按照顺序进行配置,使用驼峰开启,可省略resultMap表明参数 标签不显示,需要的自己百度添加,,,无语

yycer commented 5 years ago

① user_sex、nick_name比什么id贴心太多了 ② 多数据源也非常棒

非常值得我学习!

huaipengwang commented 5 years ago

开始还是好的,突然报错了,Cannot determine embedded database driver class for database type NONE 网上找了一大推方法都不行,能指导下吗

chenxuemeng commented 5 years ago
111
remmus2018 commented 5 years ago

MyBatis-Plus

Strong-Man commented 5 years ago

用第一种的话,怎么运行,自动生成entity?mapper里面也是自动生成的吗?

githubcbb commented 5 years ago

@huaipengwang 开始还是好的,突然报错了,Cannot determine embedded database driver class for database type NONE 网上找了一大推方法都不行,能指导下吗

告诉你,你把.properties文件换成yml试试,

@huaipengwang 开始还是好的,突然报错了,Cannot determine embedded database driver class for database type NONE 网上找了一大推方法都不行,能指导下吗

告诉你,你把.properties文件换成yml试试,我就发生这种情况,总觉得写在properties中的druid连接池无法解析我配置的driver导致一直找不到驱动,但是一换成yml立马搞定

KimGuo commented 5 years ago

建议极简xml里面还是把XML文件头加上吧……不然一眼看上去好像完整的,照着敲IDEA里面还不知道错在哪挺崩溃的

tianjiwuhen7 commented 5 years ago

第一种方法,需要自己建库,建表,test通过。

james4444 commented 4 years ago

使用注解的方式 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'user_sex' from result set. Cause: java.lang.IllegalArgumentException: No enum constant com.neo.enums.UserSexEnum.男

t812206236 commented 4 years ago

mybatis有自动生成pojo、mapper、interface的工具mbg