MySQL数据表window字段导致SQLSyntaxErrorException异常

最开始建有数据表room,该表中有一个字段window表示该房间是否有窗,room数据表信息如下:

使用MyBatis—plus在进行添加房间信息时报错,报错内容如下:

Error updating database.  Cause: java.sql.SQLSyntaxErrorException: 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 'window, ……

反思自己并没有做数据库存储的逻辑,更没有重写sql语句,都是由Mybatis-plus完成;根据提示,先检查数据表中window字段,最简单方法就是跟换一个字段名,于是我改为win:

修改Room实体类中window属性:

/**
     * 房间是否有窗子
     */
    @TableField(value = "win")
    private Boolean window;

再次尝试插入相同数据:

{
	"hotelId": 8,
	"name": "豆蔻",
	"price": 599.99,
        "state": 1,
	"images": [
		"http://www.mafengwo.cn/photo/10183/scenery_23596148/1A.html",
		"http://www.mafengwo.cn/photo/10183/scenery_23596148/2A.html",
		"http://www.mafengwo.cn/photo/10183/scenery_23596148/3A.html"
	],
	"breakfast": false,
	"wifi": true,
	"area": 35,
	"height": 3,
	"window": true,
	"bedType": "大床房",
    "other": "备注信息"
}

最后返回了成功数据:

{
	"code": 200,
	"message": "操作成功",
	"data": null
}

总结:应该时MySQL中使用window作为了关键字,不建议使用window作为字段名。

posted @ 2022-07-07 14:36  三淳  阅读(185)  评论(0编辑  收藏  举报