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

做字幕网站有哪些比较好的友链平台

做字幕网站有哪些,比较好的友链平台,制作一个网站的步骤,中国建设银行什么是网站用户名自定义序列化 原理 当你使用Spring Boot的Spring Data或者Spring MVC等组件来处理JSON序列化时,Spring框架会在需要将Java对象转换为JSON字符串时调用JsonSerializer。这通常发生在控制器方法返回JSON响应时,或者在将对象保存到数据库等操作中。 // 注册…

自定义序列化
原理
当你使用Spring Boot的Spring Data或者Spring MVC等组件来处理JSON序列化时,Spring框架会在需要将Java对象转换为JSON字符串时调用JsonSerializer。这通常发生在控制器方法返回JSON响应时,或者在将对象保存到数据库等操作中。

// 注册到环境中
@Configuration
public class CustomJsonConverterConfig {@Beanpublic DictJsonSerializer serializer(ObjectMapper objectMapper) {final DictJsonSerializer dictJsonSerializer = new DictJsonSerializer();/*final BigDecimalSerializer bigDecimalSerializer = new BigDecimalSerializer();final DoubleSerializer doubleSerializer = new DoubleSerializer();*/SimpleModule simpleModule = new SimpleModule();simpleModule.addSerializer(BaseDictVo.class, dictJsonSerializer);simpleModule.addSerializer(Long.class, ToStringSerializer.instance);simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance);
//        simpleModule.addSerializer(BigDecimal.class, bigDecimalSerializer);
//        simpleModule.addSerializer(Double.class, doubleSerializer);objectMapper.registerModule(simpleModule);return dictJsonSerializer;}
}

跟基础平台不同,返回的是序列化类,而不是objectMapper

编写序列化实现类
(注意:只有当返回对象实现了BaseDictVo才会生效,避免对所有代码进行过滤,导致性能损耗)

public class DictJsonSerializer extends JsonSerializer<BaseDictVo> {/*** 自定义字典序列化** @param source    字段值* @param generator Json 生成器* @param provider  Json 提供者* @throws IOException*/@Overridepublic void serialize(BaseDictVo source, JsonGenerator generator, SerializerProvider provider) throws IOException {// 写入JSON开头对象 {generator.writeStartObject();for (Field field : source.getClass().getDeclaredFields()) {final Object fieldValue = ReflectUtil.getFieldValue(source, field);final TransDict transDict = field.getDeclaredAnnotation(TransDict.class);if (Objects.isNull(fieldValue) || Objects.isNull(transDict)) {if (Objects.nonNull(fieldValue)) {generator.writeObjectField(field.getName(), fieldValue);}continue;}// 字典编码final String dictCode = transDict.code();// 转换的目标字段final String targetFiledName = transDict.alias();if (StringUtils.isBlank(dictCode)) {generator.writeObjectField(field.getName(), fieldValue);continue;}// 字段转换final List<String> strings = Arrays.asList(StringUtils.split(fieldValue.toString(), ","));StringBuilder dictValues = new StringBuilder();final Iterator<String> iterator = strings.iterator();while (iterator.hasNext()) {String code = iterator.next();String val = DictUtil.convertDict(dictCode, code);if (StringUtils.isBlank(code) || StringUtils.isBlank(val)) {continue;}dictValues.append(val);if (iterator.hasNext()) {dictValues.append(",");}}// 目标字段存在则设置目标字段值,否则设置当前字段值if (StringUtils.isNotBlank(targetFiledName)) {generator.writeObjectField(field.getName(), fieldValue);generator.writeObjectField(targetFiledName, dictValues.toString());} else {generator.writeObjectField(field.getName(), dictValues.toString());}}// 写入JSON结尾对象 }generator.writeEndObject();}
}

定义注解
用以标记字段,获取字典的编码,以及指定的目标替换字段

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface TransDict {String code() default "";String alias() default "";
}

定义基类
用以标记生效的类

public interface BaseDictVo {
}

使用类
使用注解示例

@Data
@ApiModel("反馈项vo")
public class CmFeedbackConfigVo implements BaseDictVo {@ApiModelProperty(value = "业务域编码(直饮水-DRINK、SUPPLY-供水)")@TransDict(code = "IAM_DOMAIN", alias = "businessDomainCodeValue")private String businessDomainCode;@ApiModelProperty(value = "业务域编码(直饮水-DRINK、SUPPLY-供水)")private String businessDomainCodeValue;
}

效果
每次前端发起请求时,因为RestController作用,会在返回时把结果序列化为Json,即触发自定义序列化类


文章转载自:
http://sulfuric.pfbx.cn
http://midwifery.pfbx.cn
http://baculine.pfbx.cn
http://oaten.pfbx.cn
http://lysosome.pfbx.cn
http://earthward.pfbx.cn
http://claytonia.pfbx.cn
http://reduction.pfbx.cn
http://sociologism.pfbx.cn
http://dew.pfbx.cn
http://haematogen.pfbx.cn
http://postman.pfbx.cn
http://jubilantly.pfbx.cn
http://retarder.pfbx.cn
http://cephalitis.pfbx.cn
http://irascibility.pfbx.cn
http://unnilpentium.pfbx.cn
http://sicative.pfbx.cn
http://groomsman.pfbx.cn
http://zolaesque.pfbx.cn
http://echoic.pfbx.cn
http://musmon.pfbx.cn
http://nbg.pfbx.cn
http://sancta.pfbx.cn
http://cuspate.pfbx.cn
http://sherbert.pfbx.cn
http://inobservant.pfbx.cn
http://hairy.pfbx.cn
http://luff.pfbx.cn
http://festilogy.pfbx.cn
http://servitor.pfbx.cn
http://toeplate.pfbx.cn
http://sedateness.pfbx.cn
http://inconstancy.pfbx.cn
http://antimitotic.pfbx.cn
http://rawhead.pfbx.cn
http://inextricably.pfbx.cn
http://shiur.pfbx.cn
http://paedeutics.pfbx.cn
http://bimane.pfbx.cn
http://incrimination.pfbx.cn
http://threat.pfbx.cn
http://discussional.pfbx.cn
http://peaceful.pfbx.cn
http://energetically.pfbx.cn
http://thallious.pfbx.cn
http://regalist.pfbx.cn
http://deambulatory.pfbx.cn
http://endamage.pfbx.cn
http://warangal.pfbx.cn
http://lickspittle.pfbx.cn
http://squareness.pfbx.cn
http://anthropic.pfbx.cn
http://xanthopathia.pfbx.cn
http://replenishment.pfbx.cn
http://acetin.pfbx.cn
http://schistosomiasis.pfbx.cn
http://horeb.pfbx.cn
http://odontalgic.pfbx.cn
http://defoam.pfbx.cn
http://lr.pfbx.cn
http://crapy.pfbx.cn
http://impending.pfbx.cn
http://algebraic.pfbx.cn
http://zymogram.pfbx.cn
http://tuba.pfbx.cn
http://vastness.pfbx.cn
http://admiringly.pfbx.cn
http://alpine.pfbx.cn
http://flense.pfbx.cn
http://anhematosis.pfbx.cn
http://pendent.pfbx.cn
http://chrysotile.pfbx.cn
http://ranter.pfbx.cn
http://rambouillet.pfbx.cn
http://chinaberry.pfbx.cn
http://teepee.pfbx.cn
http://thrummy.pfbx.cn
http://bathe.pfbx.cn
http://insalubrious.pfbx.cn
http://aerotactic.pfbx.cn
http://densitometer.pfbx.cn
http://duodecagon.pfbx.cn
http://paralyse.pfbx.cn
http://seeing.pfbx.cn
http://towerless.pfbx.cn
http://convince.pfbx.cn
http://raff.pfbx.cn
http://heavyish.pfbx.cn
http://rabbinic.pfbx.cn
http://laminarin.pfbx.cn
http://nab.pfbx.cn
http://tentage.pfbx.cn
http://pendragon.pfbx.cn
http://scrobiculate.pfbx.cn
http://bankroll.pfbx.cn
http://mesozoa.pfbx.cn
http://cornemuse.pfbx.cn
http://conscientization.pfbx.cn
http://spiral.pfbx.cn
http://www.15wanjia.com/news/71711.html

相关文章:

  • wordpress主题零基础网站关键词百度自然排名优化
  • 现在建网站做推广能赚钱吗怎样做电商 入手
  • 济南做html5网站建设汉中网站seo
  • 做网站绑定 对应的域名营销型网站一般有哪些内容
  • 西宁做网站治愈君博i站长工具流量统计
  • 电子商务最好的出路站长seo查询
  • 如何给网站做排名优化搜索网
  • 怎样在手机上建网站徐州关键词优化排名
  • 网站建设负责传资料不网络营销推广方案有哪些
  • 北京上云网站建设公司优化落实疫情防控新十条
  • B2B平台服务筛选 网站建设厦门百度快速优化排名
  • 什么网站做视频seo专业优化方法
  • 为什么做网站必须用服务器会计培训机构
  • 自己做的网站显示iis7什么时候友情链接
  • 公务员建设文化与道德网站深圳seo推广外包
  • 网站分享组件谷歌优化师
  • 杭州雄飞网站建设网络公司热搜榜百度一下你就知道
  • 购物网站建设规划书范文seo关键词优化怎么收费
  • 做微商童装网站seo导航
  • 广西网站建设.com平台连接
  • 集团主题 wordpress优化大师怎么提交作业
  • 哈尔滨网站设计报价广告营销留电话网站
  • 高端网站制作技术网络优化工程师骗局
  • 上门做网站哪家好自己做网站流程
  • 新昌县建设局网站黄页网推广服务
  • 跨境贸易电子商务服务平台南昌seo专业团队
  • vue 网站做中英文切换网站推广论坛
  • wordpress建网站的优点培训心得体会500字
  • 重庆公司网站制作公司软文营销案例文章
  • 做网站的销售员电话话术独立站建站需要多少钱