Mybatis³£¼ûµÄnogetterÒì³£
1.1 ÎÊÌâ
ʹÓÃmybatis¿ò¼Ü£¬Ð´Êý¾Ý¿â²Ù×÷·½·¨Ê±£¬½ö´«ÈëÁ˵¥¸öÊý¾Ý£¬±ÈÈçString»òÕßintÀàÐ͵ģ¬ºÜÈÝÒ׳öÏÖnogetterµÄÒì³££º
±í1
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named xxxx in 'class java.lang.String' |
ÔÒò:MybatisĬÈϲÉÓÃOGNL½âÎö²ÎÊý£¬ËùÒÔ»á×Ô¶¯²ÉÓöÔÏóÊ÷µÄÐÎʽȡ string.xxx Öµ£¬Èç¹ûûÔÚÔÚ·½·¨Öж¨Òå,Ôò»áÅ×Òì³£±¨´í¡£
1.2 ½â¾ö·½Ê½1
°Ñ#{xxx}ÐÞ¸ÄΪ #{_parameter} ¼´¿É
ÐÞ¸ÄÇ°µÄ´úÂ룺
±í2
<select id="getBookingCount" resultType="int" parameterType="string">
select count(*) from TB_EMPC_BOOKING_ORDER T
where (t.state = '1' or t.state = '2')
and t.appointmenttime = #{state}
</select>
|
Ð޸ĺóµÄ´úÂ룺
±í3
<select id="getBookingCount" resultType="int" parameterType="string">
select count(*) from TB_EMPC_BOOKING_ORDER T
where (t.state = '1' or t.state = '2')
and t.appointmenttime =#{_parameter}
</select>
|
Èç¹ûÖ»ÓÐÒ»¸ö²ÎÊý£¬ÄÇô_parameter¾Í´ú±í¸Ã²ÎÊý¡£
¶øÈç¹ûÓжà¸ö²ÎÊý£¬ÄÇô_parameter¿ÉÒÔget(0)µÃµ½µÚÒ»¸ö²ÎÊý£º
±í4
<insert id="insert" parameterType="User" useGeneratedKeys="true" keyProperty="id"> .... <if test='_parameter.get("0").name != null'>
.... </insert> |
ͨ¹ýparameter.get(0)µÃµ½µÚÒ»¸ö²ÎÊý¼´user,
#{0.name,jdbcType=CHAR}--¡·Í¨¹ý0.nameÈ·±£µÚÒ»¸ö²ÎÊýuserµÄnameÊôÐÔÖµ
ÕâÖÖ·½Ê½ºÜÉÙÈ¥Ó¦Óá£
1.3 ½â¾ö·½Ê½2
½â¾ö°ì·¨ÎªÔÚDao½Ó¿Ú²ã¼ÓÉÏ@parm¡£
±í5
public Person getPersonById(@Param("uid") Integer uid);
»òÕßÊÇ public Person getPersonById(@Param("uid") String uid); |
Ò²¿ÉÒÔÕâÑù£º@Param(value="state")