当前位置: 首页 > news >正文

本机iis网站长沙网络营销外包哪家好

本机iis网站,长沙网络营销外包哪家好,中美网站建设差异,网站建设:宏智网络科技完整的 FakeRegistrationController 代码,这让我可以全面分析后端逻辑,特别是为什么空的字段(如 compareDate)不返回给前端。我将详细分析代码的每个接口,尤其是与 list 请求和字段返回相关的部分,并解释原…

完整的 FakeRegistrationController 代码,这让我可以全面分析后端逻辑,特别是为什么空的字段(如 compareDate)不返回给前端。我将详细分析代码的每个接口,尤其是与 list 请求和字段返回相关的部分,并解释原因。


代码结构总览

FakeRegistrationController 是一个 RESTful 控制器,提供了三个接口:

  1. POST /fakeRegistration/registration/save:保存或修改假货登记信息。
  2. POST /fakeRegistration/compare/save:保存或修改比对结果。
  3. GET /fakeRegistration/list:获取假货登记列表(对应前端的 qlist 请求)。

我们关心的是 list 接口,因为它直接决定了前端表格接收到的数据内容,特别是为何空的 compareDate 不返回。


详细分析 list 接口

接口定义
@GetMapping("list")
@ApiOperation("假货登记列表")
public BaseResult list(@ApiIgnore @SessionAttribute(Constants.ADMIN_ID) Integer adminId,BasePage page) {Integer vipAdminId = copywritingApiService.getVipAdminId(adminId, 11);Page<FakeRegistration> fakeRegistrationPage = fakeRegistrationService.findByAdminId(vipAdminId, page);List<FakeRegistration> fakeRegistrations = fakeRegistrationPage.getContent();List<FakeRegistrationListDTO> fakeRegistrationListDTOS = new ArrayList<>();for (FakeRegistration fakeRegistration: fakeRegistrations) {FakeRegistrationListDTO fakeRegistrationListDTO = JSON.parseObject(JSON.toJSONString(fakeRegistration), FakeRegistrationListDTO.class);if (null != fakeRegistration.getProductId()) {Product product = productService.findById(fakeRegistration.getProductId()).orElseThrow(() -> new RuntimeException("未找到商品信息"));fakeRegistrationListDTO.setProductName(product.getName());}Admin creator = adminService.findById(fakeRegistration.getCreatorId()).orElseThrow(() -> new RuntimeException("未找到创建人信息"));fakeRegistrationListDTO.setCreatorName(StringUtils.isEmpty(creator.getNickname()) ? creator.getUsername() : creator.getNickname());fakeRegistrationListDTO.setGenuineIdentificationPoints(fakeRegistrationApiService.findIdentification(fakeRegistration.getId(), 1));fakeRegistrationListDTO.setFakeIdentificationPoints(fakeRegistrationApiService.findIdentification(fakeRegistration.getId(), 0));fakeRegistrationListDTOS.add(fakeRegistrationListDTO);}return BaseResult.success(new PageImpl<>(fakeRegistrationListDTOS, PageRequest.of(fakeRegistrationPage.getNumber(), fakeRegistrationPage.getSize()), fakeRegistrationPage.getTotalElements()));
}
数据流分析
  1. 数据查询

    • fakeRegistrationService.findByAdminId(vipAdminId, page) 返回一个 Page<FakeRegistration>,其中 FakeRegistration 是数据库实体类,包含所有字段(如 id, createdDate, compareDate, comparisonStatus 等)。
    • fakeRegistrations 是分页内容的 List<FakeRegistration>
  2. 数据转换

    • 每个 FakeRegistration 被转换为 FakeRegistrationListDTO
      FakeRegistrationListDTO fakeRegistrationListDTO = JSON.parseObject(JSON.toJSONString(fakeRegistration), FakeRegistrationListDTO.class);
      
    • 这里使用了 FastJSON(com.alibaba.fastjson.JSON)进行序列化和反序列化:
      • JSON.toJSONString(fakeRegistration)FakeRegistration 转为 JSON 字符串。
      • JSON.parseObject(..., FakeRegistrationListDTO.class) 将 JSON 字符串转为 FakeRegistrationListDTO 对象。
    • 然后手动补充了:
      • productName:从 ProductService 获取。
      • creatorName:从 AdminService 获取。
      • genuineIdentificationPointsfakeIdentificationPoints:从 FakeRegistrationApiService 获取。
  3. 返回结果

    • 返回一个 PageImpl<FakeRegistrationListDTO>,最终被序列化为 JSON 响应。
为什么空的字段(如 compareDate)不返回?
  • FastJSON 的默认行为

    • FastJSON 在序列化时,默认忽略 null 值字段,除非显式配置 SerializerFeature.WriteMapNullValue
    • 如果 FakeRegistrationcompareDatenullJSON.toJSONString(fakeRegistration) 生成的 JSON 字符串不会包含 "compareDate"
    • 示例:
      FakeRegistration fr = new FakeRegistration();
      fr.setId(34);
      fr.setComparisonStatus(1);
      fr.setCompareDate(null); // 为空
      String json = JSON.toJSONString(fr);
      // 输出: {"id":34,"comparisonStatus":1}
      
    • 反序列化到 FakeRegistrationListDTO 时,由于 JSON 中没有 compareDatefakeRegistrationListDTOcompareDate 字段不会被赋值,最终返回的 JSON 也不会包含它。
  • 业务逻辑

    • 从其他接口看,compareDate 只有在 compare/save 接口保存比对结果时才会设置:
      fakeRegistrationOrigin.setCompareDate(new Date());
      
    • registration/save 接口中,新建记录时没有设置 compareDate,它保持为 null
    • 因此,未完成比对的记录(comparisonStatus = 01)在数据库中 compareDate 就是 NULL,序列化后被忽略。
  • DTO 定义的影响

    • 如果 FakeRegistrationListDTO 中定义了 compareDate
      public class FakeRegistrationListDTO {private Integer id;private Date compareDate; // 假设是这样// 其他字段
      }
      
    • JSON.parseObject 处理没有 compareDate 的 JSON 时,fakeRegistrationListDTO.compareDate 会是 null,但后续的序列化(返回给前端时)仍由 FastJSON 处理,又会被忽略。

其他接口的补充分析

1. registration/save
@PostMapping("registration/save")
public BaseResult save(@RequestBody FakeRegistration fakeRegistration, ...) {if(null != fakeRegistration.getId()) {FakeRegistration fakeRegistrationOrigin = fakeRegistrationService.findById(fakeRegistration.getId()).orElseThrow(...);fakeRegistration = SqlUtil.mergeObject(fakeRegistration, fakeRegistrationOrigin);if(null != fakeRegistration.getCompareResult() && fakeRegistration.getCompareResult() == 1) {fakeRegistrationOrigin.setComparisonStatus(3);} else if(null != fakeRegistration.getCompareResult() && fakeRegistration.getCompareResult() == 0) {fakeRegistrationOrigin.setComparisonStatus(2);}} else {fakeRegistration.setAdminId(vipAdminId);fakeRegistration.setCreatorId(adminId);}fakeRegistration = fakeRegistrationService.save(fakeRegistration);...
}
  • 关键点
    • 新建记录时(fakeRegistration.getId() == null),只设置了 adminIdcreatorId,没有初始化 compareDate,它默认为 null
    • 修改记录时,如果提供了 compareResult,会更新 comparisonStatus,但不会设置 compareDate
    • 因此,compareDate 在这个接口中始终不会被赋值。
2. compare/save
@PostMapping("compare/save")
public BaseResult compareSave(@RequestBody FakeRegistrationSaveDTO fakeRegistration, ...) {FakeRegistration fakeRegistrationOrigin = fakeRegistrationService.findById(fakeRegistration.getId()).orElseThrow(...);fakeRegistrationOrigin.setCompareResult(fakeRegistration.getCompareResult());fakeRegistrationOrigin.setCompareDate(new Date());fakeRegistrationService.save(fakeRegistrationOrigin);...
}
  • 关键点
    • 这里显式设置了 compareDate = new Date(),表示比对完成的时间。
    • 只有通过这个接口保存比对结果时,compareDate 才会被赋值。
    • 这解释了前端数据中,只有 comparisonStatus = 2 或更高状态的记录有 compareDate

综合结论:为什么空的字段不返回?

  1. 数据来源

    • compareDate 在数据库中默认为 NULL,除非通过 compare/save 接口保存比对结果时才会被赋值。
    • 未完成比对的记录(comparisonStatus = 01)没有 compareDate 值。
  2. FastJSON 序列化

    • list 接口中,JSON.toJSONString(fakeRegistration)FakeRegistration 转为 JSON 时,默认忽略 null 字段。
    • 如果 compareDatenull,它不会出现在 JSON 字符串中。
    • 反序列化到 FakeRegistrationListDTO 后,compareDate 仍未被赋值,最终返回的 JSON 也不包含这个字段。
  3. 业务逻辑

    • 设计上,compareDate 只有在比对完成时才有意义,未完成时保持 null 并被忽略是合理的。
  4. 最终返回

    • Spring Boot 的 @RestController 使用 Jackson(或其他配置)将 PageImpl<FakeRegistrationListDTO> 序列化为 JSON,同样忽略 null 字段,进一步确保空的 compareDate 不出现在响应中。

前端数据的验证

你的前端数据:

  • id: 34, 33, 32comparisonStatus = 01):没有 compareDate,因为未调用 compare/save
  • id: 31, 30, 28comparisonStatus = 2):有 compareDate,因为通过 compare/save 设置了值。

改进建议

如果希望空的 compareDate 也返回(例如 "compareDate": null):

  1. 修改 FastJSON 配置

    FakeRegistrationListDTO fakeRegistrationListDTO = JSON.parseObject(JSON.toJSONString(fakeRegistration, SerializerFeature.WriteMapNullValue),FakeRegistrationListDTO.class
    );
    
    • 添加 WriteMapNullValue,确保 null 字段被包含。
  2. 调整 DTO

    • FakeRegistrationListDTO 中显式处理:
      fakeRegistrationListDTO.setCompareDate(fakeRegistration.getCompareDate() != null ? fakeRegistration.getCompareDate() : null);
      
  3. 全局配置

    • 在 Spring Boot 中配置 Jackson:
      @Bean
      public ObjectMapper objectMapper() {ObjectMapper mapper = new ObjectMapper();mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);return mapper;
      }
      

总结

空的 compareDate 不返回给前端是因为:

  • 业务逻辑:未完成比对时,数据库中 compareDateNULL
  • FastJSON 默认行为JSON.toJSONString 忽略 null 字段。
  • 设计选择:后端选择不返回无意义的空字段。

这种行为是合理的,但如果前端需要一致性,可以通过上述方式调整后端返回。

在这里插入图片描述

http://www.ds6.com.cn/news/80508.html

相关文章:

  • wordpress分类显示文章西安seo代理
  • 查询网站是否过期seo资源网站 排名
  • wordpress 多人版网站关键词排名手机优化软件
  • 横岗网站建设网站建设方案外包
  • 做商务楼房型图网站惠州seo计费
  • 能领免做卡的网站登录百度账号
  • 做图模板网站有哪些网络项目资源网
  • 用vs2012怎么做网站网站排名首页
  • 建网站流程的费用外贸推广公司
  • 如何查询网站点击量运营和营销是一回事吗
  • 建设网站需求分析seo指的是搜索引擎营销
  • 优质的网站制作淘宝自动推广软件
  • 做网站推广汉狮网络百度做广告费用
  • 织梦cms做网站怎么样交易链接
  • 设计站百度视频下载
  • 中山网站建设怎么样应用商店下载安装
  • wordpress 多站点 独立域名广告投放
  • 网站安全架构免费建网站软件下载
  • 专业网站建设微信官网开发广告投放数据分析
  • 网页设计是什么行业的网站seo外链平台
  • 网站左下角命名怎么做谷歌浏览器安卓下载
  • 寮步仿做网站电商平台排名
  • 网站开发答辩ppt新媒体营销策略有哪些
  • 内部网站建设app网络推广竞价是什么
  • 网站开发怎么自动获取位置网络项目平台
  • 如何从建设局网站上更换职称人员东莞企业网站推广
  • 做的最好的视频网站廊坊百度快照优化排名
  • 做外销批发有什么网站优化设计答案五年级上册
  • 毛片a做片在线观看网站有哪些推荐就业的培训机构
  • 集团网站建设 中企动力营销培训