MyBatis出现:SQLSyntaxErrorException: Unknown column ‘XXX‘ in ‘field list‘

时间:2024-05-31 10:04:34

 <update id="updateStudent">
        update tb_students set stu_name=${stuName},stu_gender=${stuGender},stu_age=${stuAge},stu_tel=${stuTel}
        where stu_num = ${stuNum}
 </update>

本质上来说,是Mybatis使用上的错误,不熟悉,理解其实现机理所致。同样的问题,也会出现在其他语句中,所以在实现时注意数据传输的类型!!!

解决办法

加上引号

 <update id="updateStudent">
        update tb_students
        set stu_name='${stuName}',
            stu_gender='${stuGender}',
            stu_age='${stuAge}',
            stu_tel='${stuTel}'
        where stu_num = '${stuNum}'
</update>

或者进行参数化表示

 <update id="updateStudent">
    update tb_students
    set stu_name=#{stuName},
        stu_gender=#{stuGender},
        stu_gender=#{stuGender},
        stu_tel=#{stuTel}
    where stu_num = #{stuNum}
</update>