解决criteria的example不支持clob字段模糊查询问题
在使用mybatisgenerator生成数据库表的dao,model和mapper文件时,发现表中如果含有clob类型的字段时不会将其作为查询条件生成example,因此在需要对clob类型做模糊查询时需要自行在生成的example文件中自行添加该类型对应字段的查询方法:
// content字段是clob类型
public Criteria andContentLike(String value) {
addCriterion("CONTENT like", value, "content");
return (Criteria) this;
}
然后在使用criteria对象调用该方法进行模糊查询:
// params.get("content")是传入参数
if(params.get("content")!=null&&!"".equals(params.get("content"))) {
criteria.andContentLike("%"+(String)params.get("content")+"%");
}
这里不同于其他查询的地方是该方法的传入参数不仅仅是传入参数,还要在参数前后加上"%",否则无法得到查询结果。