MyBatis框架使用错误清单
一[email protected]注解
1.查询语句where条件中含有中文字符串
遇到这种情况,MyBatis控制台的查询结果集可能为空,而在MySQL查询器中会有结果,原因是因为查询语句中中文编码问题,要保证MySQL数据库的字符集与查询语句的编码字符集相同,若MySQL字符集设为UTF-8,则在springboot项目中application.yml设置数据源时应设置为如下:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql:///eshop?useUnicode=true&characterEncoding=UTF-8
username: root
password: 709498
thymeleaf:
cache: false
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
在url要连接的数据库后添加?useUnicode=true&characterEncoding=UTF-8即可。