对应的Mapper中的方法如下:<where>
<if test="参数== '标题'">
p.pro_title like concat(concat('%', #{content}),'%')
</if>
<if test="参数== '内容'">
p.pro_content like concat(concat('%',#{content}),'%')
</if>
<if test="参数== '关键字'">
p.pro_keywords like concat(concat('%',#{content}),'%')
</if>
</where>
解决之道:public List<Problem> searchByCondition(String type,String content);
第一次尝试:
结果:error。。。。<where>
<if test="type == '标题'">
p.pro_title like concat(concat('%', #{content}),'%')
</if>
<if test="type == '内容'">
p.pro_content like concat(concat('%',#{content}),'%')
</if>
<if test="type == '关键字'">
p.pro_keywords like concat(concat('%',#{content}),'%')
</if>
</where>
第二次尝试:
结果:Success!!!public List<Problem>
searchByCondition(@Param(value="type") String type,@Param(value="content") String content);
结论:Mybatis如何知道参数是type,在Mapper里添加@Param(value="type")就可以了!