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

3.5.5

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

使用updateById()方法的时候,出现了部分字段添加异常

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

这是我数据库对应的封装的实体类

@Data
@TableName("pms_category")
public class CategoryEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 分类id
     */
    @TableId(value = "cat_id")
    private Long catId;
    /**
     * 分类名称
     */
    @TableField("name")
    private String name;
    /**
     * 父分类id
     */
    @TableField("parent_cid")
    private Long parentCid;
    /**
     * 层级
     */
    @TableField("cat_level")
    private Integer catLevel;
    /**
     * 是否显示[0-不显示,1显示]
     */
    @TableField("show_status")
    @TableLogic(value = "1",delval = "0")
    private Integer showStatus;
    /**
     * 排序
     */
    @TableField("sort")
    private Integer sort;
    /**
     * 图标地址
     */
    @TableField("icon")
    private String icon;
    /**
     * 计量单位
     */
    @TableField("product_unit")
    private String productUnit;
    /**
     * 商品数量
     */
    @TableField("product_count")
    private Integer productCount;

    /**
     * 子分类标签数据
     */
    @TableField(exist = false)
    private List<CategoryEntity> children;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CategoryEntity that = (CategoryEntity) o;
        return Objects.equals(catId, that.catId) && Objects.equals(name, that.name) && Objects.equals(parentCid, that.parentCid) && Objects.equals(catLevel, that.catLevel) && Objects.equals(showStatus, that.showStatus) && Objects.equals(sort, that.sort) && Objects.equals(icon, that.icon) && Objects.equals(productUnit, that.productUnit) && Objects.equals(productCount, that.productCount) && Objects.equals(children, that.children);
    }

    @Override
    public int hashCode() {
        return Objects.hash(catId, name, parentCid, catLevel, showStatus, sort, icon, productUnit, productCount, children);
    }


}

在我的业务代码中,直接使用updateById进行数据的更新

@RequestMapping("/update")
    //@RequiresPermissions("gulimallproduct:category:update")
    public R update(@RequestBody CategoryEntity category){
        categoryService.updateById(category);

        return R.ok();
    }

我们对数据库ID为225的数据进行修改:只修改name,icon , product_unit 三个字段的内容 此时打了断点,可以看到后端接收到的实体类的数据没有问题 放行后执行完毕,没有报错,日志中的SQL语句也正常 Preparing: UPDATE pms_category SET name=?, icon=?, product_unit=? WHERE cat_id=? AND show_status=1 2024-04-07T15:18:47.549+08:00 DEBUG 14900 --- [gulimall-product] [io-10000-exec-6] c.e.g.mapper.CategoryDao.updateById : ==> Parameters: 手手手手(String), 123(String), 123(String), 225(Long) 2024-04-07T15:18:47.551+08:00 DEBUG 14900 --- [gulimall-product] [io-10000-exec-6] c.e.g.mapper.CategoryDao.updateById : <== Updates: 1 2024-04-07T15:18:47.571+08:00 DEBUG 14900 --- [gulimall-product] [io-10000-exec-7] c.e.g.mapper.CategoryDao.selectList : ==> Preparing: SELECT cat_id,name,parent_cid,cat_level,show_status,sort,icon,product_unit,product_count FROM pms_category WHERE show_status=1 2024-04-07T15:18:47.571+08:00 DEBUG 14900 --- [gulimall-product] [io-10000-exec-7] c.e.g.mapper.CategoryDao.selectList : ==> Parameters: 2024-04-07T15:18:47.584+08:00 DEBUG 14900 --- [gulimall-product] [io-10000-exec-7] c.e.g.mapper.CategoryDao.selectList : <== Total: 1423 但是到数据库查看数据/前端刷新再次查找的时候就会发现name字段的属性变为了 四个问号 ???? 225 ???? 34 3 1 0 123 123 0 多次尝试也是如此,目前只对修改后的name内容为中文的时候会出现这个问题,如果输入后为英文不会出现问题,检查过数据库的编码格式utf8,而且手动输入SQL语句修改数据是没问题的

报错信息

无报错

Comment From: miemieYaho

你数据库链接的url指定编码了吗?

Comment From: VampireAchao

Thank you for your detailed description. Based on the information you've provided, this issue might be related to character encoding handling. Please check the following points:

  1. Confirm whether the MyBatis-Plus configuration file's database connection URL includes characterEncoding=UTF-8.
  2. Check if the database connection driver is up to date and supports UTF-8 encoding.
  3. Re-verify that the encoding settings for the database, tables, and fields are indeed set to UTF-8.
  4. If the request passes through any middleware, check if they could potentially alter character encoding.
  5. Examine the default character encoding settings of the application server to ensure it's set to UTF-8.
  6. Consider setting the JVM startup parameter -Dfile.encoding=UTF-8 to enforce UTF-8 encoding.

If the above steps do not resolve the issue?Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.