There is a need to implement multi-condition query, and then mybaits uses map to pass parameters, and it keeps reporting errors at the beginning: Caused by: org.apache.ibatis.binding.BindingException: Parameter'pcode' not fond , that is, my parameters It has not been passed in. Then I searched it and found that there was a problem with my map parameter transfer.
Next , let’s go directly to the code.
//controller层
public Result<?> searchPolice(PageInfo pageInfo, @RequestBody JSONObject jsonObject) {
Result<Page<PoliceInfo>> result = new Result<>();
try {
Map<String, Object> map = jsonObject.getInnerMap();
Page<PoliceInfo> page = new Page<>(pageInfo.getCurrentPage(), pageInfo.getPageSize());
List<PoliceInfo> list = policeInfoService.getPoliceInfoByConditions(page, map);
page.setRecords(list);
result.setSuccess(true);
result.setCode(200);
result.setResult(page);
} catch (Exception e) {
result.error500("查询失败" + e.getMessage());
log.error(e.getMessage(), e);
}
return result;
}
//service层
public List<PoliceInfo> getPoliceInfoByConditions(Page page, Map<String, Object> map) {
return policeInfoMapper.getPoliceInfoByConditions(page, map);
}
//mapper层
List<PoliceInfo> getPoliceInfoByConditions(Page page, @Param("params") Map<String, Object> map);
//xml文件
<select id="getPoliceInfoByConditions" parameterType="java.util.Map"
resultType="org.jeecg.modules.schedule.entity.PoliceInfo">
select * from XXX where DEPT=#{
params.dept}
<if test="params.pcode!= null and params.pcode !=''">
and pcode=#{
params.pcode}
</if>
<if test="params.name != null and params.name !=''">
and name=#{
params.name}
</if>
<if test="params.xb != null and params.xb !=''">
and xb=#{
params.xb}
</if>
<if test="params.sfzhm != null and params.sfzhm !=''">
and sfzhm=#{
params.sfzhm}
</if>
<if test="params.zw != null and params.zw !=''">
and zw=#{
params.zw}
</if>
<if test="params.gs != null and params.gs !=''">
and gs=#{
params.gs}
</if>
<if test="params.zc != null and params.zc !=''">
and zc=#{
params.zc}
</if>
<if test="params.blyx != null and params.blyx !=''">
and blyx=#{
params.blyx}
</if>
<if test="params.zl != null and params.zl !=''">
and zl=#{
zl}
</if>
<if test="params.sj != null and params.sj !=''">
and sj=#{
sj}
</if>
<if test="params.iszzjy != null and params.iszzjy !=''">
and iszzjy=#{
iszzjy}
</if>
<if test="params.age1 != null and params.age1 !='' and params.age2 != null and params.age2 !=''">
and nl between #{
params.age1} and #{
params.age2}
</if>
</select>
Record the pits left by the first use of map transfer~