idea中SQL使用带中文的查询条件查不到记录
我最近在做毕设,做到搜索模块时,用到模糊查询中参数name是中文的,一直查不到数据
在dao中写的注释查询
@Select("select * from product where name like concat('%',#{name},'%')")
List<Product> queryByName(String name);
在配置文件中
url: jdbc:mysql://localhost:3306/test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
解决办法:
把配置文件中useUnicode=true改成characterEncoding=UTF-8
url: jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC