问答详情
源自:3-11 用户模型管理--用户注册功能实现02

语法错误,关于UserPasswordDOMapper的,请大神帮忙看下。。。

2019-06-03 21:56:29.690  WARN 36608 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.jdbc.BadSqlGrammarException: 

### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

### The error may involve com.miaoshaproject.dao.UserPasswordDOMapper.insertSelective-Inline

### The error occurred while setting parameters

### SQL: insert into user_password

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]

上面是报的错


<insert id="insertSelective" parameterType="com.miaoshaproject.dataObject.UserPasswordDO">
  insert into user_password
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="id != null">
      id,
    </if>
    <if test="encrptPassword != null">
      encrpt_password,
    </if>
    <if test="userId != null">
      user_id,
    </if>
  </trim>
  <trim prefix="values (" suffix=")" suffixOverrides=",">
    <if test="id != null">
      #{id,jdbcType=INTEGER},
    </if>
    <if test="encrptPassword != null">
      #{encrptPassword,jdbcType=VARCHAR},
    </if>
    <if test="userId != null">
      #{userId,jdbcType=INTEGER},
    </if>
  </trim>
</insert>

上面是我对应的mappper里面的sql语句



https://img2.mukewang.com/5cf527ca00019b3f03750379.jpg

这个是本人创建的数据库


class UserPasswordDO {
    private Integer id;

    private String encrptPassword;

    private Integer userId;

    public UserPasswordDO(Integer id, String encrptPassword, Integer userId) {
        this.id = id;
        this.encrptPassword = encrptPassword;
        this.userId = userId;
    }

    public UserPasswordDO() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getEncrptPassword() {
        return encrptPassword;
    }

    public void setEncrptPassword(String encrptPassword) {
        this.encrptPassword = encrptPassword == null ? null : encrptPassword.trim();
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }
}

这是对应的dataObjext 



难受啊

提问者:慕函数7093388 2019-06-03 22:00

个回答

  • FigSprite
    2019-06-04 11:03:25
    已采纳

    直接debug查userPassDO的值也行,debug用不惯的话,可以直接在UserPassDO.class里写toString()方法,然后打印出来看看值

  • 慕娘8285708
    2019-10-08 20:18:44

    请问楼主最后怎么解决的嘞?

  • qq_慕标3189372
    2019-06-04 21:16:37

    往user_password表中插入的时候id是没有默认值的,视频里是怎么直接插进去的啊?

  • FigSprite
    2019-06-04 10:59:49

    你可以试着打印一下

    userPasswordDO

    对象看看里面的userid字段是不是空,可能之前建表的时候你没有设初始值,然后就会这个亚子,

    接下来看看UserDOMapper.xml里面的插入语句是否写了主键返回获得,把这个获得的主键传给UserModel,然后把这个UserModel传给组装userPassWordDO的方法里,看看行不行