一:发现问题java
sql动态语句中若是 parameterType="int"sql
<select id="sel_campusinfo" parameterType="int" resultType="Campusinfo">
select cmpid,cmpname from campusinfo where state!='d' and cmpid=#{cmpid}
</select>mybatis
是正确的,可是若是加上if testide
<select id="sel_campusinfo" parameterType="int" resultType="Campusinfo">
select cmpid,cmpname from campusinfo where state!='d' and cmpid!=0
<if test="cmpid!=0">and cmpid=#{cmpid}</if>
</select>spa
则报错:.net
There is no getter for property named 'cmpid' in 'class java.lang.Integer'orm
出错缘由:Mybatis默认采用ONGL解析参数,因此会自动采用对象树的形式取Integer.cmpid。Integer对象没有cmpid属性。若是不解析参数,mybatis自动识别传入的参数,不会报错。对象
二:解决办法
1.修改select语句blog
<select id="sel_campusinfo" parameterType="int" resultType="Campusinfo">
select cmpid,cmpname from campusinfo where state!='d' and cmpid!=0
<if test="_parameter!=0">and cmpid=#{_parameter}</if>
</select>接口
参数名所有改成_parameter。
2.不修改sql,只修改接口
接口类:
Campusinfo sel_campusinfo( int cmpid);
改成:
Campusinfo sel_campusinfo(@Param(value="cmpid") int cmpid);