在sql语句中为了实现inset允许插入空字段,我用了下面的方法,但是报错。
<sql id="deptValue">
<trim suffix="" suffixOverrides=",">
<if test="deptName != null and deptName != '' ">
 #{deptName},
</if>
<if test="keyinId != null and keyinId != '' ">
#{keyinId},
</if>
<if test="deptTel != null and deptTel != '' ">
#{deptTel},
</if>
<if test="supervisorId != null and supervisorId != '' ">
#{supervisorId},
</if>
<if test="contactId != null and contactId != '' ">
 #{contactId},
</if>
<if test="deptNote != null and deptNote != '' ">
 #{deptNote},
</if>
<if test="deptFatherId != null and deptFatherId != '' ">
#{deptFatherId},
</if>
</trim>
</sql> <sql id="deptColumn">
<trim suffix="" suffixOverrides=",">
<if test="vc_dept_name != null and vc_dept_name != '' ">
vc_dept_name,
</if>
<if test="n_keyin_id != null and n_keyin_id != '' ">
n_keyin_id,
</if>
<if test="vc_dept_tel != null and vc_dept_tel != '' ">
vc_dept_tel,
</if>
<if test="n_dept_supervisor_id != null and n_dept_supervisor_id != '' ">
n_dept_supervisor_id,
</if>
<if test="n_dept_contact_id != null and n_dept_contact_id != '' ">
n_dept_contact_id,
</if>
<if test="vc_note != null and vc_note != '' ">
vc_note,
</if>
<if test="n_dept_father_id != null and n_dept_father_id != '' ">
n_dept_father_id,
</if>
</trim>
</sql> <insert id="InsertDept" parameterType="dept">
insert into t_dept(<include refid="deptColumn"/>)
    values(<include refid="deptValue"/>)
</insert>报错:There is no getter for property named 'vc_dept_name' in 'class com.leidun.rights.model.Dept'当我在com.leidun.rights.model.Dept类中创建相应的vc_dept_name,就不报错了。但是这个是我的表字段名,我不想在Dept中创建该属性。我该怎么办?

解决方案 »

  1.   


    insert into t_dept(<include refid="deptColumn"/>)
    values(<include refid="deptValue"/>)
    就是这个啊。
      

  2.   

    没有明白,那你为什么要在动态sql里拼是否为空呢,你插入的判断条件应该列与值应该是相同吧,不然
    <if test="deptName != null and deptName != '' ">这数据成立了,<if test="vc_dept_name != null and vc_dept_name != '' ">不成立,那sql肯定是不对的,还有你的bean应该提供getter,mybatis是通过get得到bean的值,不然没办判断