使用mybatis查询,经常会碰到类似下面这样的代码
public Waybill findByPhone(String name) {
WaybillExample example = new WaybillExample();
example.createCriteria().andRoadNameEqualTo(name);
List<Waybill> list = waybillMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
1、演示
我一想这个代码不是很常见吗,每次写都要浪费一点时间,着实不是我这样的懒虫程序员能够忍受的,所以我新建了一个模板来快速生成代码,最终结果如下
在代码出输入findone,会提示自动生成上面的代码
输入enter确定,会自动出现下面代码,是不是省了好多事
public Waybill findByPhone(String name) {
WaybillExample example = new WaybillExample();
example.createCriteria().and;
List<Waybill> list = waybillMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
}
2、自定义模板
template text:如下
$RETURNNAME$Example example = new $RETURNNAME$Example();
example.createCriteria().and$END$;
List<$RETURNNAME$> list = $RETURNNAME1$Mapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
}
return null;
点击右边的Edit variables
最后点击下面的change,选择java,应用保存就能使用了