在使用模糊查询的时候,mysql使用的是最左原则,所以模糊查询语句:

select * from sys_user where user_name like '#{userName}%'

我们会限制userName:仅支持中文,字母,特殊字符

那么如果查询的输入框中使用 '','%' 来匹配的话,会全量查询,而不是我们想要的 '','%' 开头的匹配列;

解决

在查询的时进行转义:

user.setUserName(user.getUserName.replaceAll("_","\\\\_").replaceAll("%","\\\\%"))

mysql通配符

%:匹配任何字符出现任意次数
_:匹配单个字符

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-02-22
  • 2021-10-26
  • 2022-02-10
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2021-05-31
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-08-12
  • 2021-09-15
  • 2022-12-23
相关资源
相似解决方案