Parameter ‘deptName‘ not found.

2 篇文章 0 订阅

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值