There is no getter for property named 'pid' in 'class java.lang.Long'
2017-09-15 17:32
531 查看
今天再做mybatis项目的时候突然爆出了这个错误,在网络上查来查去大多说的都不是很正确,特此对此问题做个批注
关门放代码
<select id="findAllDept" parameterType="Long" resultMap="deptResultMap">
SELECT
DEP_ID,
DEP_NAME,
PARENT_ID,
DEP_DESP,
FROM NULLID.DEPARTMENT_B
<where>
<if test="pid != null">
DEP_ID=#{pid}
</if>
</where>
</select>
就是这样一段简单的代码报了上述的错误,网络上说的原因大多是因为传进来的参数是Long,所以在#{pid}中应将pid改为_parameter,即应该为#{_parameter},但是我在更改过后问题依然没有解决,后来我发现了<if test="pid !=null">这里的这个pid,按照常理来说 这个pid很可能被解析为对象的属性值,因为对字符串的解析更容易出错嘛,将其改为<if test="_parameter !=null">后问题果然迎刃而解,并且及时#{}中的值依然为pid,也没有再报错。
正确的方式为:
<select id="findAllDept" parameterType="Long" resultMap="deptResultMap">
SELECT
DEP_ID,
DEP_NAME,
PARENT_ID,
DEP_DESP,
FROM NULLID.DEPARTMENT_B
<where>
<if test="_parameter != null">
DEP_ID=#{pid}
</if>
</where>
</select>
关门放代码
<select id="findAllDept" parameterType="Long" resultMap="deptResultMap">
SELECT
DEP_ID,
DEP_NAME,
PARENT_ID,
DEP_DESP,
FROM NULLID.DEPARTMENT_B
<where>
<if test="pid != null">
DEP_ID=#{pid}
</if>
</where>
</select>
就是这样一段简单的代码报了上述的错误,网络上说的原因大多是因为传进来的参数是Long,所以在#{pid}中应将pid改为_parameter,即应该为#{_parameter},但是我在更改过后问题依然没有解决,后来我发现了<if test="pid !=null">这里的这个pid,按照常理来说 这个pid很可能被解析为对象的属性值,因为对字符串的解析更容易出错嘛,将其改为<if test="_parameter !=null">后问题果然迎刃而解,并且及时#{}中的值依然为pid,也没有再报错。
正确的方式为:
<select id="findAllDept" parameterType="Long" resultMap="deptResultMap">
SELECT
DEP_ID,
DEP_NAME,
PARENT_ID,
DEP_DESP,
FROM NULLID.DEPARTMENT_B
<where>
<if test="_parameter != null">
DEP_ID=#{pid}
</if>
</where>
</select>
相关文章推荐
- There is no getter for property named 'xxx' in 'class java.lang.Long'
- There is no getter for property named 'expertGoodAtId' in 'class java.lang.Long'
- 解决“There is no getter for property named 'XXX' in 'class java.lang.Long'"
- mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.Long'
- There is no getter for property named 'xxx' in 'class java.lang.Long'
- Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。
- mybatis报错 There is no getter for property named 'xx' in 'class java.lang.String
- Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。
- There is no getter for property named 'XXX' in 'class java.lang.XXX
- There is no getter for property named 'email' in 'class java.lang.String'
- Mybatis-There is no getter for property named 'id' in 'class java.lang.String'
- 关于Mybatis "There is no getter for property named 'XXX' in class java.lang.String"的问题
- There is no getter for property named 'XX' in 'class java.lang.String'
- 错误解决:There is no getter for property named 'id' in class 'java.lang.String'
- Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'
- There is no getter for property named 'email' in 'class java.lang.String
- Mybatis-There is no getter for property named 'id' in 'class java.lang.String'
- mybatis加Spring项目: 解决There is no getter for property named '***' in 'class java.lang.String'问题
- Mybatis There is no getter for property named 'XXX' in 'class java.lang.XXX
- There is no getter for property named 'XXX' in 'class java.lang.String'