使用mybatis时,处理postgresql保留关键字的最佳方法是什么

ao218c7q  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(661)

当我创建一个类似 namepassword 在postgresql 13中也是如此。postgresql可能会将其视为保留关键字。因此,mybatis sql希望:

INSERT INTO apple_server_notification_record (created_time, updated_time, notification_type, auto_renew_product_id, auto_renew_status, auto_renew_status_change_date, auto_renew_status_change_date_ms, auto_renew_status_change_date_pst, environment, `password`, bid, bvrs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

它将自动在sql中添加``。但在postgresql 13中执行sql时,显示以下错误:

org.springframework.jdbc.BadSqlGrammarException: 

### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "`"

  Position: 249

### The error may exist in class path resource [mybatis/mapper/dolphin/AppleServerNotificationRecordMapper.xml]

### The error may involve com.dolphin.soa.post.dao.AppleServerNotificationRecordMapper.insertSelective-Inline

### The error occurred while setting parameters

### SQL: INSERT INTO apple_server_notification_record (created_time, updated_time, notification_type, auto_renew_product_id, auto_renew_status, auto_renew_status_change_date, auto_renew_status_change_date_ms, auto_renew_status_change_date_pst, environment, `password`, bid, bvrs) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

### Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "`"

  Position: 249
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "`"
  Position: 249

我可以通过更改列来解决它 passwordapple_auth_password ,我知道它会解决问题。但在我的代码中,我必须在从apple接收请求时显式转换Map。我的实体定义如下:

private String password;

有什么好的建议来解决这个问题吗?遇到这个问题你会怎么做?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题