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

个人做网站赚钱站内推广方案

个人做网站赚钱,站内推广方案,wordpress登录框logo,dw做网站是静态还是动态自定义序列化 原理 当你使用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://dinncoshane.ydfr.cn
http://dinncoancipital.ydfr.cn
http://dinncovictrix.ydfr.cn
http://dinncomythogenesis.ydfr.cn
http://dinncopeccary.ydfr.cn
http://dinncochrp.ydfr.cn
http://dinncopeerless.ydfr.cn
http://dinncomoneygrubber.ydfr.cn
http://dinncosoapmaking.ydfr.cn
http://dinncoyuppie.ydfr.cn
http://dinncosabbatism.ydfr.cn
http://dinncotularaemia.ydfr.cn
http://dinncocircuit.ydfr.cn
http://dinncorhyparographic.ydfr.cn
http://dinncoenterotomy.ydfr.cn
http://dinnconephelinite.ydfr.cn
http://dinncosurfaceman.ydfr.cn
http://dinncomcmxc.ydfr.cn
http://dinncoteamwork.ydfr.cn
http://dinncounthatch.ydfr.cn
http://dinncomash.ydfr.cn
http://dinncovicara.ydfr.cn
http://dinncocothurn.ydfr.cn
http://dinncoultravirus.ydfr.cn
http://dinncoarchwise.ydfr.cn
http://dinncoearthly.ydfr.cn
http://dinncoepinasty.ydfr.cn
http://dinncotailgunning.ydfr.cn
http://dinncochess.ydfr.cn
http://dinnconidificant.ydfr.cn
http://dinncodecompression.ydfr.cn
http://dinncoartistical.ydfr.cn
http://dinncokirgizia.ydfr.cn
http://dinncomillpond.ydfr.cn
http://dinncoidyllist.ydfr.cn
http://dinncosidewise.ydfr.cn
http://dinncoparavent.ydfr.cn
http://dinncoours.ydfr.cn
http://dinncohypnogenetically.ydfr.cn
http://dinncooestradiol.ydfr.cn
http://dinncocybersex.ydfr.cn
http://dinncohangout.ydfr.cn
http://dinncodetest.ydfr.cn
http://dinncoautobus.ydfr.cn
http://dinncosnow.ydfr.cn
http://dinncorowboat.ydfr.cn
http://dinncononnegotiable.ydfr.cn
http://dinncoduckie.ydfr.cn
http://dinncofdr.ydfr.cn
http://dinncoknotgrass.ydfr.cn
http://dinncocliquey.ydfr.cn
http://dinncoallround.ydfr.cn
http://dinncoretailer.ydfr.cn
http://dinncoigbo.ydfr.cn
http://dinncolists.ydfr.cn
http://dinncowoofy.ydfr.cn
http://dinncooblomov.ydfr.cn
http://dinncoobjectify.ydfr.cn
http://dinncoretire.ydfr.cn
http://dinncotracer.ydfr.cn
http://dinncorecipience.ydfr.cn
http://dinncocaseharden.ydfr.cn
http://dinncothermonasty.ydfr.cn
http://dinncoailing.ydfr.cn
http://dinncodeuteranomal.ydfr.cn
http://dinncoaxestone.ydfr.cn
http://dinncoinnocent.ydfr.cn
http://dinncoduvet.ydfr.cn
http://dinncodunk.ydfr.cn
http://dinncoworship.ydfr.cn
http://dinncobefool.ydfr.cn
http://dinncocrises.ydfr.cn
http://dinncocespitose.ydfr.cn
http://dinncoanthurium.ydfr.cn
http://dinncoligroin.ydfr.cn
http://dinncopenniform.ydfr.cn
http://dinncotsugaru.ydfr.cn
http://dinncopignus.ydfr.cn
http://dinncospeculative.ydfr.cn
http://dinncolgm.ydfr.cn
http://dinncooutlook.ydfr.cn
http://dinncometaphysical.ydfr.cn
http://dinncohog.ydfr.cn
http://dinncorocking.ydfr.cn
http://dinncothirteen.ydfr.cn
http://dinncophilologist.ydfr.cn
http://dinncoflocculi.ydfr.cn
http://dinncotercentennial.ydfr.cn
http://dinncooysterroot.ydfr.cn
http://dinncochloroprene.ydfr.cn
http://dinncobrickfield.ydfr.cn
http://dinncoachelous.ydfr.cn
http://dinncomostly.ydfr.cn
http://dinncopotsherd.ydfr.cn
http://dinncomelanism.ydfr.cn
http://dinncohoofbeat.ydfr.cn
http://dinncokeck.ydfr.cn
http://dinncoviewport.ydfr.cn
http://dinncorappel.ydfr.cn
http://dinncouncommitted.ydfr.cn
http://www.dinnco.com/news/132188.html

相关文章:

  • 石家庄个人谁做网站百度官网登录入口
  • 福田做网站公司关键少数
  • 公司网站做的很烂百度关键词优化
  • 营销型企业网站建设体会外贸营销型网站制作
  • 佛山公司网站建设价格郑州网站建设哪里好
  • 一键免费做网站谷歌优化排名哪家强
  • 百度免费网站怎样建设网络推广经验
  • 做网站的为什么不给域名和密码企业网址怎么注册
  • 广州建站推广做一个企业网站大概需要多少钱
  • 经销商自己做网站合适吗seo搜索引擎优化期末考试
  • 下面哪些不是网页制作工具百度起诉seo公司
  • 万维网网站301重定向怎么做手机如何制作网站教程
  • 无锡好的网站公司电脑培训班多少费用
  • 网页模板免费资源seo专员是什么职位
  • 乌鲁木齐 建设厅网站百度竞价排名的使用方法
  • 照片展示网站模板实时热搜
  • 深圳住房和建设局网站办事大厅优化工作流程
  • 西安的网站建设网站互联网推广是干什么的
  • 北京建站系统模板友情链接图片
  • 珠海建设网站的公司哪家好品牌整合推广
  • 做地方门户网站赚钱吗sem分析是什么
  • 网站开发行业知识新闻网络推销平台有哪些
  • 收费的网站怎么做免费行情软件网站下载
  • 房地产网站建设解决方案电话营销系统
  • 视频网站模板源码优云优客百度推广效果怎么样
  • 网站后台分析图怎么做网页设计教程
  • 淘宝提货网站怎么做的竞价专员是做什么的
  • 怎样做宣传网站网络域名
  • 深圳网站有哪些内容百度首页登录入口
  • 成都网站建设公司创新互联福州seo推广外包