为了账号安全,请及时绑定邮箱和手机立即绑定

自己在后台拼凑一个userModel,但是数据插入失败

https://img1.sycdn.imooc.com//5c4583eb0001115809600618.jpg

上面是拼凑好的userModel,传给userServiceImpl,执行到下面这一步就。。。。

https://img1.sycdn.imooc.com//5c4585a400015c0a05200056.jpg

报错如下:

=======================================================================

2019-01-21 16:32:45.673  WARN 13744 --- [nio-8080-exec-2] .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.UserDOMapper.insertSelective-Inline

### The error occurred while setting parameters

### SQL: insert into user_info

### 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]

=======================================================================

这报错什么鬼?我是谁?我在哪里?我要不要找UserDOMapper.insertSelective喝喝茶?

正在回答

1 回答

解决了,就是下面标黑的两个变量调换了,弄得userDO里的变量都为null,在写入mysql时报错如题所示

// 实现userModel->user data object方法
private UserDO convertFromUserModel(UserModel userModel) {
    if (userModel == null) {
        return null;
    }

    UserDO userDO = new UserDO();
    // 将userModel的属性赋予给userDO
    BeanUtils.copyProperties();
    return userDO;
}


0 回复 有任何疑惑可以回复我~
#1

斯基姆斯 提问者

BeanUtils.copyProperties(userModel, userDO);
2019-01-21 回复 有任何疑惑可以回复我~
#2

慕的地3081565

题主,怎么解决的呀w,我这还是不行
2019-03-16 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

自己在后台拼凑一个userModel,但是数据插入失败

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信