当然归根结底这不是MyBatis的问题而是SQL语句的问题,已知mybatis的逆向模型会自动把“aa-bb-cc”格式的字段整合成aaBbCc格式的变量,当然这种模式的变量仅适用于在java中传递或处理,等进入到xml中依然要用到原来的sql字段名,所以也必须要遵从sql的命名格式。
默认的insert语句不会对原字段进行修饰,所以需要手动添加反引号,即键盘上方紧挨着1的符号。
将 message-to-send 修改为 `message-to-send`
<insert id="insert" parameterType="com.SoftAdmin.bean.Admintalkroom" >
insert into admintalkroom (id, username, year,
month, day, `message-to-send`,
hour, minute)
values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{year,jdbcType=VARCHAR},
#{month,jdbcType=VARCHAR}, #{day,jdbcType=VARCHAR}, #{messageToSend,jdbcType=VARCHAR},
#{hour,jdbcType=VARCHAR}, #{minute,jdbcType=VARCHAR})
</insert>