当前使用版本(必填,否则不予处理)

3.4.2

该问题是如何引起的?(确定最新版也有问题再提!!!)

全局配置了逻辑删除字段的已删除值和未删除值,但是在注解上没有配置的话将不生效,必须要注解配置了才能生效。

重现步骤(如果有就写完整)

全局配置如下:

#mybatis plus
mybatis-plus:
  global-config:
    db-config:
      logic-delete-field: deletedAt
      logic-delete-value: now()
      logic-not-delete-value: null
  mapper-locations: classpath:mapper/*.xml

实体类逻辑删除注解什么也没配置:

 @TableLogic()
  private Date deletedAt;     //删除时间

打印的sql:

2021-04-07 17:22:57 | DEBUG | main | com.wantai.communication.dao.UserMapper.selectById | ==>  Preparing: SELECT id,name,real_name,telephone,id_card,disabled,password,empno,default_role_id,created_at,gender,updated_at,deleted_at,img_name FROM t_user WHERE id=? AND deleted_at=
2021-04-07 17:22:58 | DEBUG | main | com.wantai.communication.dao.UserMapper.selectById | ==> Parameters: 42(Integer)

执行结果:报错!

如果逻辑删除字段注解加上配置: ``` @TableLogic(value = "null",delval = "now()") private Date deletedAt; //删除时间

打印的sql:

2021-04-07 17:28:37 | DEBUG | main | com.wantai.communication.dao.UserMapper.selectById | ==> Preparing: SELECT id,name,real_name,telephone,id_card,disabled,password,empno,default_role_id,created_at,gender,updated_at,deleted_at,img_name FROM t_user WHERE id=? AND deleted_at IS NULL 2021-04-07 17:28:37 | DEBUG | main | com.wantai.communication.dao.UserMapper.selectById | ==> Parameters: 42(Integer) 2021-04-07 17:28:38 | DEBUG | main | com.wantai.communication.dao.UserMapper.selectById | <== Total: 0

执行结果:正常。

### 报错信息

org.springframework.jdbc.BadSqlGrammarException:

Error querying 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 '' at line 1

The error may exist in com/wantai/communication/dao/UserMapper.java (best guess)

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT id,name,real_name,telephone,id_card,disabled,password,empno,default_role_id,created_at,gender,updated_at,deleted_at,img_name FROM t_user WHERE id=? AND deleted_at=

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 '' at line 1

; bad SQL grammar []; nested exception is 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 '' at line 1




**Comment From: miemieYaho**

yml:   logic-not-delete-value: `null`

**Comment From: kim709394**

> yml: logic-not-delete-value: `null`

全局配置是有配置的了。

**Comment From: miemieYaho**

![image](https://user-images.githubusercontent.com/28334419/113985972-4fadf080-987f-11eb-8db8-c3361c4abc2b.png)


**Comment From: kim709394**

  logic-not-delete-value: `null`

**Comment From: kim709394**

  logic-not-delete-value: `null`

Caused by: while scanning for the next token found character '' that cannot start any token. (Do not use for indentation) in 'reader', line 24, column 31: logic-not-delete-value: null ```

还是不行

Comment From: miemieYaho

百度搜 如何 yml 设置值为 字符串的 null

Comment From: kim709394

logic-not-delete-value: "null" 这样才行,要加上双引号才行。按道理来说应该不用加引号能识别的,因为数据库连接信息都没加引号都可以。