mybatis 查询多个条件时,报错信息如下
Caused by:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'interface_cover' not found. Available parameters are [arg1, arg0, param1, param2]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
原始sql语句
<select id="selectCountByCondition" resultType="java.lang.Integer">
select
count(*)
from service_data where interface_cover = #{interface_cover,jdbcType=VARCHAR} and `type`=#{type, jdbcType=VARCHAR}
</select>
修改为
<select id="selectCountByCondition" resultType="java.lang.Integer">
select
count(*)
from service_data where interface_cover = #{arg0,jdbcType=VARCHAR} and `type`=#{arg1, jdbcType=VARCHAR}
</select>
注意xxMapper.java中使用@Param
int queryTheWeekCount(@Param("interface_cover") String interface_cover, @Param("type") Integer type);
mybatis的xxDoMapper.java中@Param("MM") String MM必须和Domapper.xml中保持一致
List<UnitCaseResultDO> selectResultByCondition(@Param("appkey") String appkey, @Param("weekNumber") Integer weekNumber, @Param("caseErrorMsg") String caseErrorMsg);
<if test="weekNumber != null and weekNumber != ''">
AND week_number=#{weekNumber, jdbcType=BIGINT}
</if>
<if test="caseErrorMsg != null and caseErrorMsg != ''">
AND case_error_msg=#{caseErrorMsg, jdbcType=VARCHAR}
</if>