baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.35k stars 4.31k forks source link

被查询数据的字段值包含反斜杠时,反斜杠被转译的问题 #5779

Closed xhy1999 closed 11 months ago

xhy1999 commented 11 months ago

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

操作系统: Win10 22H2 Java: JDK_1.8.0_291 数据库: MySQL 5.7.34 (字符集utf8mb4) 依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.6.6</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.4</version>
</dependency>

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

数据库连接地址:jdbc:mysql://127.0.0.1:3306/db_test?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai 实体类:

@Data
@TableName("cm_test")
public class CmTestEntity {

    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    private Integer id;
    /**
     * 用户id
     */
    private String userId;
    /**
     * 文件路径1
     */
    private String filePath1;
    /**
     * 文件路径2
     */
    private String filePath2;

}

Mapper:

@Mapper
public interface CmTestMapper extends BaseMapper<CmTestEntity> {

}

Service:

public interface CmTestService extends IService<CmTestEntity> {

}

ServiceImpl:

@Service
public class CmTestServiceImpl extends ServiceImpl<CmTestMapper, CmTestEntity> implements CmTestService {

}

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

@Component
public class TestHelper {

    @Resource
    private CmTestMapper cmTestMapper;

    public void test() {
        CmTestEntity entity = new CmTestEntity();
        entity.setUserId("10001");
        entity.setFilePath1("C:\\Projects\\Java\\cloud\\Upload\\Common\\test\\10\\10001\\20231115_131808615_2.ve");
        entity.setFilePath2("C:\\Projects\\Java\\cloud\\Upload\\Common\\test\\10\\10001\\20231115_131808615_2.pr");
        cmTestMapper.insert(entity);
        List<CmTestEntity> dataList = cmTestMapper.selectList(
                Wrappers.<CmTestEntity>lambdaQuery()
                        .eq(CmTestEntity::getUserId, "10001")
        );
        System.out.println(dataList.get(0).getFilePath1());
        System.out.println(dataList.get(0).getFilePath2());
    }

}

执行test()后日志输出:

C:\Projects\Java\cloud\Upload\Common\test\10\10001\20231115_131808615_2.ve
C:\Projects\Java\cloud\Upload\Common\test\10\10001\20231115_131808615_2.pr
miemieYaho commented 11 months ago

和mp无关

xhy1999 commented 11 months ago

目前我这边debug下来,发现在org.apache.ibatis.executor.resultset.DefaultResultSetHandlerapplyAutomaticMappings方法中final Object value = mapping.typeHandler.getResult(rsw.getResultSet(), mapping.column);这一行获取的结果出现了而非\

miemieYaho commented 11 months ago

看类名,那是mybatis的

xhy1999 commented 11 months ago

是的是的,我发现了,不好意思额

xhy1999 commented 11 months ago

最终发现是数据库表的字符集设置成了ujis,将其改为utf8就正常了,实在不好意思