• 我原先的mybatislike拼接方式

    <select id="exampleSql">
      select 
         id, name
      from
        example_table
      where 
        name like '%${name}%'
    </select>
    
  • 更好的mybatislike拼接方式

    <select id="exampleSql">
      select 
        id, name
      from 
        example_table
      where
        name like concat('%', '#{name}', '%')
    </select>
    

总结: 用SQL原有的concat方法去拼接字符而不是用myatbis${xxx}方式去拼接,mybatis的${xxx}方式有SQL注入风险,一来可以避免在Service层去校验传递参数,而来更加直观