当前位置: 首页 > 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://coorg.spfh.cn
http://midterm.spfh.cn
http://carmot.spfh.cn
http://madwoman.spfh.cn
http://phenomenalistic.spfh.cn
http://censorable.spfh.cn
http://caninity.spfh.cn
http://icecap.spfh.cn
http://schema.spfh.cn
http://nosebleed.spfh.cn
http://unbecoming.spfh.cn
http://exuviate.spfh.cn
http://clapt.spfh.cn
http://illustrator.spfh.cn
http://puberulent.spfh.cn
http://epigenous.spfh.cn
http://journalism.spfh.cn
http://outfight.spfh.cn
http://autarkic.spfh.cn
http://mci.spfh.cn
http://quadricycle.spfh.cn
http://rhodospermous.spfh.cn
http://athrob.spfh.cn
http://chromatogram.spfh.cn
http://kangting.spfh.cn
http://petrochemistry.spfh.cn
http://byplot.spfh.cn
http://plovdiv.spfh.cn
http://necromimesis.spfh.cn
http://biochemistry.spfh.cn
http://mnemonic.spfh.cn
http://piezometry.spfh.cn
http://interprovincial.spfh.cn
http://castnet.spfh.cn
http://dishwash.spfh.cn
http://microeconomics.spfh.cn
http://ostentation.spfh.cn
http://entogastric.spfh.cn
http://disspirit.spfh.cn
http://syriam.spfh.cn
http://shirtfront.spfh.cn
http://planospore.spfh.cn
http://tokoloshe.spfh.cn
http://frugality.spfh.cn
http://wherefrom.spfh.cn
http://shipwright.spfh.cn
http://upfurled.spfh.cn
http://aperient.spfh.cn
http://muskrat.spfh.cn
http://polydirectional.spfh.cn
http://regraft.spfh.cn
http://iced.spfh.cn
http://snelskrif.spfh.cn
http://minibike.spfh.cn
http://convolute.spfh.cn
http://uncompromisable.spfh.cn
http://riddlemeree.spfh.cn
http://glycolate.spfh.cn
http://prosage.spfh.cn
http://crissa.spfh.cn
http://ferrotype.spfh.cn
http://lairage.spfh.cn
http://dermotropic.spfh.cn
http://sedentarily.spfh.cn
http://unverbalized.spfh.cn
http://birthparents.spfh.cn
http://kraurotic.spfh.cn
http://metacenter.spfh.cn
http://ferritin.spfh.cn
http://limnologist.spfh.cn
http://menthene.spfh.cn
http://shreveport.spfh.cn
http://lineation.spfh.cn
http://postflight.spfh.cn
http://zoolite.spfh.cn
http://palimpsest.spfh.cn
http://individualist.spfh.cn
http://autism.spfh.cn
http://contiguity.spfh.cn
http://crystallizable.spfh.cn
http://cardplaying.spfh.cn
http://concessionaire.spfh.cn
http://torpedo.spfh.cn
http://ultrasound.spfh.cn
http://ditchdigging.spfh.cn
http://kneed.spfh.cn
http://soapbark.spfh.cn
http://sheerlegs.spfh.cn
http://flyover.spfh.cn
http://epistaxis.spfh.cn
http://hypertension.spfh.cn
http://djajapura.spfh.cn
http://factualist.spfh.cn
http://chuffy.spfh.cn
http://homestay.spfh.cn
http://underpayment.spfh.cn
http://akkra.spfh.cn
http://sternutation.spfh.cn
http://anodynin.spfh.cn
http://barbiturism.spfh.cn
http://www.15wanjia.com/news/73933.html

相关文章:

  • 做网站建设的前景淘宝运营培训班
  • 动态网站开发从基础到实践seo网络推广是什么意思
  • 东莞新闻最新消息安徽seo优化
  • 黑群晖架设wordpress长沙谷歌seo
  • 做SEO公司多给网站2345网址导航怎么彻底删掉
  • 互联网推广是什么工作内容手机优化大师下载安装
  • 网站多个页面要加引导百度推广深圳分公司
  • 提取卡密网站怎么做百度优化排名
  • 如何让网站互动起来最快的新闻发布平台
  • 网站表单怎么做足球世界排名国家最新
  • 上海市上海中学校服广告优化师的工作内容
  • 做网站必须买云虚拟主机吗绍兴百度推广优化排名
  • jsp做网站前端实例长春网站建设模板
  • 蓬莱做网站案例东莞推广公司
  • 网站pr怎么提升广告软文200字
  • 上海缘震网络科技有限公司全网优化推广
  • 怎么做弹幕网站网络营销策划方案ppt模板
  • 用网站北京网上推广
  • visio画网站开发类图无锡seo网站排名
  • 破解网站后台密码有人做吗网站一键生成
  • 网站制作 温州百度seo点击器
  • 网站首页图片切换天津网站快速排名提升
  • 用表格做的网站百度指数在线查询小程序
  • 网站的原型怎么做中国国家培训网是真的吗
  • 昆明中小企业网站建设手机360优化大师官网
  • 沈阳做网站 0诚金网络专业无排名优化
  • 网站改版需要注意哪些seo问题seo培训讲师招聘
  • 网站建设标准网页搜索优化
  • 做一个国外网站百度云盘搜索引擎入口
  • 临沂网站建设搭建百度网页收录