当前使用版本(必填,否则不予处理)
3.5.3.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
使用postgresql数据库配置了column-format对字段名加引号最终的sql语句并没有加引号
mybatis-plus: global-config: db-config: column-format: "\"%s\"" configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
试了几种格式配置都不行
column-format: "\"%s\""
column-format: "%s"
column-format: '"%s"'
重现步骤(如果有就写完整)
实体类:
@TableName("public.session")
public class Session {
@TableId(type = IdType.AUTO)
private Long id;
@TableField
private String session;
@TableField
private Integer status;
@TableField
private Long userId;
}
表结构:
CREATE TABLE IF NOT EXISTS public.session
(
id bigint NOT NULL DEFAULT nextval('session_id_seq'::regclass),
session character varying(256) COLLATE pg_catalog."default" NOT NULL DEFAULT ''::character varying,
status smallint NOT NULL DEFAULT 0,
"creationTime" timestamp without time zone NOT NULL DEFAULT now(),
"userId" bigint NOT NULL DEFAULT 0,
CONSTRAINT session_pkey PRIMARY KEY (id),
CONSTRAINT session_unique UNIQUE (session)
)
报错信息
### SQL: INSERT INTO public.session ( session, userId ) VALUES ( ?, ? )
### Cause: org.postgresql.util.PSQLException: 错误: 关系 "session" 的 "userid" 字段不存在
位置:41
; bad SQL grammar []] with root cause
只有明确的在实体属性上写明字段名才行
@TableField("\"userId\"")
private Long userId;
Comment From: nieqiurong
mybatis-plus:
global-config:
db-config:
column-format: '"%s"'
看着这种写法没啥问题,你检查一下配置是否因为缩进什么问题导致没有生效把,或者提供一个小工程过来排查看看
Comment From: qmdx
yaml mybatis-plus: global-config: db-config: column-format: '"%s"'看着这种写法没啥问题,你检查一下配置是否因为缩进什么问题导致没有生效把,或者提供一个小工程过来排查看看
如上如果使用 @TableField 注解可能会导致失效,需要配置属性 设置为
@TableField( , keepGlobalFormat=true )
Comment From: Jven00
我也遇到了。application.yaml配置如下:
mybatis-plus.global-config.db-config.column-format: "%s"
实体类:
@TableField(keepGlobalFormat = true, value = "order")
private Integer order;
执行sql报错:### SQL: SELECT id,parent_id,dir_name,dir_path,type,create_time,update_time,project_code,order FROM t_ds_repository_dir WHERE (type = ? AND project_code = ?)\r\n### 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 'order FROM t_ds_repository_dir \n \n WHERE (type = 1 AND project_code = 1)' at line 1\n; bad SQL grammar [];