Parameter ‘runState’ not found.
报错信息为Parameter ‘deptName’ not found.时,是因为xml中的sql标签写法出现错误
dao接口代码:
public List<CargoBudgetReport> query(String[] ids);
mapper.xml的错误代码:
<select id="queryClassReport" parameterType="list" resultType="com.duay.mavenoa.bean.ClassReport">
select c.* from classreport c, dept, emp
<where>
c.empId=emp.empId and emp.deptId=dept.deptId
<if test="deptName !=null" >
<trim prefix="and">
<foreach collection="array" open="deptName in(" close=")" item="deptName" separator=",">
#{deptName}
</foreach>
</trim>
</if>
</where>
</select>
mapper.xml的正确代码:
<select id="queryClassReport" parameterType="list" resultType="com.duay.mavenoa.bean.ClassReport">
select c.* from classreport c, dept, emp
<where>
c.empId=emp.empId and emp.deptId=dept.deptId
<if test="array !=null" >
<trim prefix="and">
<foreach collection="array" open="dept.deptName in(" close=")" item="deptName" separator=",">
#{deptName}
</foreach>
</trim>
</if>
</where>
</select>
错误修改的地方为:<if test="deptName !=null" >
改为:<if test="array !=null" >
和
<foreach collection="array" open="deptName in(" close=")" item="deptName" separator=",">
改为:
<foreach collection="array" open="dept.deptName in(" close=")" item="deptName" separator=",">
如果是多参数往xml.中传值,需要以下变化,不然也会报Parameter ‘字段’ not found.
错误写法:
public List<queryReport> queryClassReport( String[] deptName, String runState, String projectState);
正确写法:
多参数的话必须加上@Param不然mapper文件是不认识的
public List<queryReport> queryClassReport(@Param("deptName") String[] deptName, @Param("runState") String runState, @Param("projectState") String projectState);
它匹配的对应的正确的mapper.xml文件的sql写法
需要注意的一点事,多参数的xml的sql要把parameterType这个属性去掉不要写
<select id="queryClassReport" resultType="com.duay.mavenoa.bean.ClassReport">
select c.* from classport c, dept, emp
<where>
c.empId=emp.empId and emp.deptId=dept.deptId
<if test="runState != null">
and c.runState=#{runState}
</if>
<if test="projectState != null">
and c.projectState=#{projectState}
</if>
<if test="deptName !=null" >
<trim prefix="and">
<foreach collection="deptName" open="dept.deptName in(" close=")" item="deptname" separator=",">
#{deptname}
</foreach>
</trim>
</if>
</where>
</select>
共同探讨学习技术创建技术氛围Day9884125