Commit e3078949 by 章家宝

refactor: 布尔字段重命名 isLongImage → longImage

  符合阿里巴巴Java开发手册规范,避免Boolean类型字段加is前缀导致的序列化问题
1 parent 0252c144
...@@ -80,7 +80,7 @@ public class ReceptionHomePageMaterialDetail implements Serializable { ...@@ -80,7 +80,7 @@ public class ReceptionHomePageMaterialDetail implements Serializable {
*/ */
@ApiModelProperty(name = "isLongImage", notes = "是否为长图(true=是 false=否)") @ApiModelProperty(name = "isLongImage", notes = "是否为长图(true=是 false=否)")
@Column(name = "is_long_image") @Column(name = "is_long_image")
private Boolean isLongImage; private Boolean longImage;
@Column(name = "created_by", insertable = false, updatable = false) @Column(name = "created_by", insertable = false, updatable = false)
private String createdBy; private String createdBy;
......
...@@ -92,7 +92,7 @@ public class ReceptionHomePageMaterialInfo implements Serializable { ...@@ -92,7 +92,7 @@ public class ReceptionHomePageMaterialInfo implements Serializable {
*/ */
@ApiModelProperty(name = "isLongImage", notes = "是否为长图(true=是 false=否)") @ApiModelProperty(name = "isLongImage", notes = "是否为长图(true=是 false=否)")
@Column(name = "is_long_image") @Column(name = "is_long_image")
private Boolean isLongImage; private Boolean longImage;
/** /**
* 素材排序 * 素材排序
......
...@@ -142,7 +142,7 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable { ...@@ -142,7 +142,7 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable {
private Integer imageHeight; private Integer imageHeight;
@ApiModelProperty(name = "isLongImage", notes = "是否为长图") @ApiModelProperty(name = "isLongImage", notes = "是否为长图")
private Boolean isLongImage; private Boolean longImage;
@ApiModelProperty(name = "materialSort", notes = "素材排序") @ApiModelProperty(name = "materialSort", notes = "素材排序")
private Integer materialSort; private Integer materialSort;
...@@ -174,7 +174,7 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable { ...@@ -174,7 +174,7 @@ public class SaveOrUpdateHomePageConfigDTO implements Serializable {
private Integer imageHeight; private Integer imageHeight;
@ApiModelProperty(name = "isLongImage", notes = "是否为长图") @ApiModelProperty(name = "isLongImage", notes = "是否为长图")
private Boolean isLongImage; private Boolean longImage;
} }
} }
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<result column="content_pic_url" property="contentPicUrl" jdbcType="VARCHAR" /> <result column="content_pic_url" property="contentPicUrl" jdbcType="VARCHAR" />
<result column="image_width" property="imageWidth" jdbcType="INTEGER" /> <result column="image_width" property="imageWidth" jdbcType="INTEGER" />
<result column="image_height" property="imageHeight" jdbcType="INTEGER" /> <result column="image_height" property="imageHeight" jdbcType="INTEGER" />
<result column="is_long_image" property="isLongImage" jdbcType="BIT" /> <result column="is_long_image" property="longImage" jdbcType="BIT" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" /> <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" /> <result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" /> <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<result column="content_pic_url" property="contentPicUrl" jdbcType="VARCHAR"/> <result column="content_pic_url" property="contentPicUrl" jdbcType="VARCHAR"/>
<result column="image_width" property="imageWidth" jdbcType="INTEGER"/> <result column="image_width" property="imageWidth" jdbcType="INTEGER"/>
<result column="image_height" property="imageHeight" jdbcType="INTEGER"/> <result column="image_height" property="imageHeight" jdbcType="INTEGER"/>
<result column="is_long_image" property="isLongImage" jdbcType="BIT"/> <result column="is_long_image" property="longImage" jdbcType="BIT"/>
<result column="material_sort" property="materialSort" jdbcType="INTEGER"/> <result column="material_sort" property="materialSort" jdbcType="INTEGER"/>
<result column="created_by" property="createdBy" jdbcType="VARCHAR"/> <result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/> <result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
INSERT INTO reception_home_page_material_info (material_type, is_show, material_title, material_name, INSERT INTO reception_home_page_material_info (material_type, is_show, material_title, material_name,
home_entrance_type, home_entrance_cover, material_sort, config_id, content_pic_url, image_width, image_height, is_long_image) VALUES( home_entrance_type, home_entrance_cover, material_sort, config_id, content_pic_url, image_width, image_height, is_long_image) VALUES(
#{info.materialType}, #{info.isShow}, #{info.materialTitle}, #{info.materialName}, #{info.homeEntranceType}, #{info.materialType}, #{info.isShow}, #{info.materialTitle}, #{info.materialName}, #{info.homeEntranceType},
#{info.homeEntranceCover}, #{info.materialSort}, #{info.configId}, #{info.contentPicUrl}, #{info.imageWidth}, #{info.imageHeight}, #{info.isLongImage}); #{info.homeEntranceCover}, #{info.materialSort}, #{info.configId}, #{info.contentPicUrl}, #{info.imageWidth}, #{info.imageHeight}, #{info.longImage});
SET @current_id = LAST_INSERT_ID(); SET @current_id = LAST_INSERT_ID();
<if test="info.materialDetailList != null and !info.materialDetailList.isEmpty()"> <if test="info.materialDetailList != null and !info.materialDetailList.isEmpty()">
<foreach collection="info.materialDetailList" item="detail"> <foreach collection="info.materialDetailList" item="detail">
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
rel_vehicle_series_id, rel_vehicle_model_name, rel_vehicle_model_id, content_pic_url, image_width, image_height, is_long_image) VALUES( rel_vehicle_series_id, rel_vehicle_model_name, rel_vehicle_model_id, content_pic_url, image_width, image_height, is_long_image) VALUES(
@current_id, #{detail.relVehicleSeriesName}, #{detail.relVehicleSeriesId}, @current_id, #{detail.relVehicleSeriesName}, #{detail.relVehicleSeriesId},
#{detail.relVehicleModelName}, #{detail.relVehicleModelName},
#{detail.relVehicleModelId}, #{detail.contentPicUrl}, #{detail.imageWidth}, #{detail.imageHeight}, #{detail.isLongImage}); #{detail.relVehicleModelId}, #{detail.contentPicUrl}, #{detail.imageWidth}, #{detail.imageHeight}, #{detail.longImage});
<!-- <if test="child.children != null and !child.children.isEmpty()">--> <!-- <if test="child.children != null and !child.children.isEmpty()">-->
<!-- <foreach collection="child.children" item="grandchild" separator=";">--> <!-- <foreach collection="child.children" item="grandchild" separator=";">-->
<!-- INSERT INTO category (name, parent_id) VALUES (#{grandchild.name}, @child_id);--> <!-- INSERT INTO category (name, parent_id) VALUES (#{grandchild.name}, @child_id);-->
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(Top 3)

    1. 违反核心规则:Dubbo/RPC API 接口的破坏性变更(高危)

    • 问题描述:在 rpc-dj-mindworkplate-api 模块下的 SaveOrUpdateHomePageConfigDTO 中,将已有请求参数 isLongImage 重命名为 longImage。
    • 影响分析:触发了“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的重要规则。API 包是提供给调用方(如前端、其他微服务)的契约。直接修改字段名会导致其对应的 Getter/Setter 发生变化(从 getIsLongImage() 变为 getLongImage())。如果调用方未同步升级依赖包并修改代码,反序列化时将无法映射该字段,导致服务端接收到的该值为 null,从而引发线上业务故障。
    • 优化建议:对于已在线上运行的 RPC DTO,不建议直接修改字段名。如果为了遵循阿里规范(Boolean 类型不加 is),必须通过序列化注解来保证向后兼容性。 代码示例(以 Jackson/Fastjson 为例): java // 保持外部 JSON/RPC 契约不变,内部 Java 字段名符合规范 @ApiModelProperty(name = "isLongImage", notes = "是否为长图") @JsonProperty("isLongImage") // 如果使用 Jackson @JSONField(name = "isLongImage") // 如果使用 Fastjson private Boolean longImage;

    2. Swagger API 文档与实际序列化字段可能存在不一致(中等)

    • 问题描述:在 Model 和 DTO 中,字段名修改为了 longImage,但上方的注解依然是 @ApiModelProperty(name = "isLongImage", ...)。
    • 影响分析:如果没有配合上述提到的 @JsonProperty 等序列化注解,默认情况下 JSON 序列化框架会将其输出为 longImage。但这会导致 Swagger 接口文档上显示的请求/响应参数名为 isLongImage,与实际 JSON 报文不符,增加前后端联调的沟通成本和错误率。
    • 优化建议:明确该字段对外的 JSON Key 到底是什么。如果对外保持 isLongImage,请补充序列化兼容注解(见问题1);如果对外也改为 longImage(前提是已确认所有调用方同步修改),则需同步修改 @ApiModelProperty(name = "longImage")。

    二、评分明细

    • 1. 功能实现的正确性与健壮性(20/40分) 扣分理由:虽然修改 MyBatis XML 的映射是正确的(没有使用子查询,且 # 占位符均已同步修改),但直接修改 API 模块的 DTO 字段名打破了向下兼容性,违反了“已有请求参数变更视为危险实现”的硬性规则,可能引发线上数据丢失,属于严重的接口契约破坏。

    • 2. 安全性与潜在风险(30/30分) 评分理由:本次变更为纯粹的字段重命名,未引入 SQL 注入、越权等安全漏洞。

    • 3. 最佳实践与可维护性(15/20分) 扣分理由:开发者主动修复违反“阿里 Java 开发手册(Boolean 属性避免 is 前缀)”的坏味道,出发点极佳,值得肯定。但最佳实践不仅包含代码规范,还包含接口演进规范。在修复规范问题时未考虑 API 的兼容性设计,且 Swagger 注解未同步对齐,故酌情扣分。

    • 4. 性能与资源利用(5/5分) 评分理由:简单的字段重命名,对系统性能和资源利用无负面影响。

    • 5. 提交信息质量(5/5分) 评分理由:Commit message 非常优秀。使用了 refactor: 语义化前缀,清晰指出了修改内容(isLongImage → longImage),并准确说明了修改动机(符合阿里规范,避免序列化问题),可追溯性极强。

    总分:75分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!