最近在工作中使用到了模糊查询结果,结果使用
@Select("SELECT g.*,t.type_name as typeName FROM goods_info as g,goods_type as t "
+ "WHERE g.goods_name LIKE %#{goodsName}% AND g.type_id = t.type_id "
+ "ORDER BY g.date_create DESC LIMIT #{start},#{size}")
@ResultMap(value = "goodsInfo")
List<GoodsInfo> queryGoodsListByName(@Param("goodsName") String goodsName,@Param("start") Integer start, @Param("size")Integer size);
结果直接报错,过百度,最终问题解决:
@Select("SELECT g.*,t.type_name as typeName FROM goods_info as g,goods_type as t "
+ "WHERE g.goods_name LIKE CONCAT('%',#{goodsName},'%') AND g.type_id = t.type_id "
+ "ORDER BY g.date_create DESC LIMIT #{start},#{size}")
@ResultMap(value = "goodsInfo")
List<GoodsInfo> queryGoodsListByName(@Param("goodsName") String goodsName,@Param("start") Integer start, @Param("size")Integer size);
MySQL中concat函数:
使用方法: CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串。如有任何一个参数为NULL,则返回值为 NULL。