mybatis自增主键无效

论坛 期权论坛 脚本     
匿名技术用户   2021-1-6 01:51   11   0
  1. 今天遇到一个很简单,但是浪费我很长时间的小问题,mybatis自增主键插入的问题,怎么测试都不正确,检查了几遍,代码没有问题啊,怎么就是一直提示我id没有default value,话不多说,先看我mybatis的代码:
  2.  <insert id="insertMessagePush" parameterType="com.workschool.base.po.MessagePushPO" useGeneratedKeys="true" keyProperty="id">
        insert into messagepush (FKWorkerId, Title,CreateTime, Remark, Content)
        values (#{fkworkerid,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{createtime,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR})
      </insert>
  3. 再看我的MessagePushPO对象:
  4. package com.workschool.base.po;
    
    import java.io.Serializable;
    
    public class MessagePushPO  implements Serializable {
    
     /**
      * [对象序列化标识]
      */
     private static final long serialVersionUID = 5941705113280080483L;
     
        private Integer id;
    
        private Integer fkworkerid;
    
        private String title;
    
        private String createtime;
    
        private String remark;
    
        private String content;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public Integer getFkworkerid() {
            return fkworkerid;
        }
    
        public void setFkworkerid(Integer fkworkerid) {
            this.fkworkerid = fkworkerid;
        }
    
        public String getTitle() {
            return title;
        }
    
        public void setTitle(String title) {
            this.title = title == null ? null : title.trim();
        }
    
        public String getCreatetime() {
            return createtime;
        }
    
        public void setCreatetime(String createtime) {
            this.createtime = createtime == null ? null : createtime.trim();
        }
    
        public String getRemark() {
            return remark;
        }
    
        public void setRemark(String remark) {
            this.remark = remark == null ? null : remark.trim();
        }
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String content) {
            this.content = content == null ? null : content.trim();
        }
    }


  5. 理论上完全没问题,但是关键问题不在这里,且看数据库库表:

  6. 注意这里id一定要勾选上自增递增,否则mybatis再怎么做都不起作用,这样就搞定啦。。
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP