SSH项目中数据库列为关键字错误处理

来源:互联网 发布:飞鱼网络电视成人 编辑:程序博客网 时间:2024/05/16 08:14

有很多时候table 的列为关键字:

例如这样:

INSERT INTO message (content, createtime, FROM, STATUS, TO, id) VALUES ('1', '1','1','1','1','2')

其中FROM , STATUS , TO  为关键字 .所以在插入的时候就会报错:

错误码: 1064
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 'from, status, to, id) values ('1', '1','1','1','1','2')' at line 1


在SSH项目中处理这种报错有一个很简单的方法,在modle 层的实体类注解一下:

@Column(name = "from", unique = false, nullable = true, insertable = true, updatable = true, length = 32)public java.lang.String getFrom() {return this.from;}


改为: 

@Column(name = "`from`", unique = false, nullable = true, insertable = true, updatable = true, length = 32)public java.lang.String getFrom() {return this.from;}

  大笑

 


然后就可以愉快的增删该查了  

0 0
原创粉丝点击