Mybatis的_parameter使用
程序员文章站
2022-07-15 13:27:07
...
之前在介绍CONCAT的用法时,入参采用的是一实体类封装形式,故parameterType参数类型是实体类,而这个则采用的是一个具体类型的参数,这时在我们判断mappper.xml中判断参数时,由于parameterType参数类型不是实体类了,判断参数时,这时就需要用_parameter来代替参数判断,如果直接采用入参的字段(如<if test="jkmc != null and jkmc != ''"
>)去判断则会报错
@RequestMapping(value = "/findEsbInterfaceByJkmcOrJkbhOrPyjp",produces = "application/json; charset=utf-8",method = RequestMethod.POST)
public Result findEsbInterfaceByJkmcOrJkbhOrPyjp(@RequestParam(name = "jkmc",required=false) String jkmc) throws Exception{
return esbInterfaceService.findEsbInterfaceByJkmcOrJkbhOrPyjp(jkmc);
}
<!--根据接口名称或接口编号或拼音简拼查询jkzt=1(正常)的接口列表-->
<select id="findEsbInterfaceByJkmcOrJkbhOrPyjp" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from ESB_INTERFACE
<where>
JKZT = '1'
<if test="_parameter != null and _parameter != ''">
and CONCAT(CONCAT(CONCAT('',jkmc),jkbh),pyjp) like '%' || #{jkmc,jdbcType=VARCHAR} || '%'
</if>
</where>
</select>