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

宠物网站建设方案外贸网站建设推广公司

宠物网站建设方案,外贸网站建设推广公司,房产管理局官网入口,企业邮箱是qq邮箱吗效果:接口会返回orderType,但是这个orderType是枚举的类型(1,2,3,4),我想多返回一个orderTypeDesc给前端展示,这样前端就可以直接拿orderTypeDesc使用了。 1. 定义注解 …

效果:接口会返回orderType,但是这个orderType是枚举的类型(1,2,3,4),我想多返回一个orderTypeDesc给前端展示,这样前端就可以直接拿orderTypeDesc使用了。

1. 定义注解

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
//作用是将当前类上的注解也追加到目标类上,如果不加的话,目标类及时加了@EnumTranslation注解,也不会集成该注解的所有注解
@JacksonAnnotationsInside
@JsonSerialize(using = EnumTranslationSerialize.class)
public @interface EnumTranslation {//生成的属性名,不写默认原名+DescString generateFieldName() default "";//参考的枚举,会根据改枚举的code获取对应的descClass<? extends Enum<?>> targetEnum() ;
}

2. 定义EnumTranslationSerialize类

EnumTranslationSerialize继承了JsonSerializer,实现了ContextualSerializer,用于序列化时多生成一个字段返回。

ContextualSerializer的作用:为了在序列化时获取属性上的注解信息,然后根据注解信息重新创建EnumTranslationSerialize来序列化,这样就能根据注解的配置来序列化了。

@Slf4j
public class EnumTranslationSerialize<E> extends JsonSerializer<Object> implements ContextualSerializer {private String targetFieldName;private LinkedHashMap<String, String> enumMap;public EnumTranslationSerialize() {//需要空构造方法,请勿删除}/*** 构造方法,获取当前属性名,生成的属性名,目标枚举*/public EnumTranslationSerialize(String fieldName, String targetFieldName, Class enumClass) {if (StringUtils.isNotBlank(targetFieldName)) {this.targetFieldName = targetFieldName;} else {this.targetFieldName = fieldName + "Name";}enumMap = new LinkedHashMap<>();try {Method getCode = enumClass.getMethod("getCode");Method getDesc = enumClass.getMethod("getDesc");for (Object everyEnum : EnumUtil.getEnumMap(enumClass).values()) {enumMap.put(getCode.invoke(everyEnum).toString(), getDesc.invoke(everyEnum).toString());}} catch (Exception e) {log.error(ExceptionUtils.getStackTrace(e));}}/*** 序列化规则*/@Overridepublic void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {if (Objects.isNull(o)) {return;}try {String codeValue = o.toString();jsonGenerator.writeString(codeValue);String value = enumMap.get(codeValue);//多写入一个属性if (Objects.nonNull(value)) {jsonGenerator.writeFieldName(this.targetFieldName);jsonGenerator.writeObject(value);}} catch (Exception e) {log.error(ExceptionUtils.getStackTrace(e));}}/*** ContextualSerializer接口的方法,作用是获取属性上的枚举*/@Overridepublic JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty beanProperty) throws JsonMappingException {if (beanProperty != null) {EnumTranslation t = beanProperty.getAnnotation(EnumTranslation.class);if (t != null) {return new EnumTranslationSerialize<>(beanProperty.getName(), t.targetFieldName(), t.enumC());}}return serializerProvider.findNullValueSerializer(beanProperty);}
}

3. 使用

@Data
public class OrderVO {@Schema(description = "订单类型")@EnumTranslation(generateFieldName = "orderTypeDesc", enumC = OrderType.class)private Long orderType;
}

文章转载自:
http://pyrargyrite.c7497.cn
http://parthenos.c7497.cn
http://jobbernowl.c7497.cn
http://materially.c7497.cn
http://amok.c7497.cn
http://jackdaw.c7497.cn
http://july.c7497.cn
http://scrutiny.c7497.cn
http://suite.c7497.cn
http://preadaptation.c7497.cn
http://quencher.c7497.cn
http://philanthropic.c7497.cn
http://corvus.c7497.cn
http://reprehensibly.c7497.cn
http://timbul.c7497.cn
http://caesium.c7497.cn
http://acetate.c7497.cn
http://antecedency.c7497.cn
http://wormwood.c7497.cn
http://transreceiver.c7497.cn
http://wharfinger.c7497.cn
http://sulfinyl.c7497.cn
http://kook.c7497.cn
http://spend.c7497.cn
http://morisco.c7497.cn
http://misguided.c7497.cn
http://outflung.c7497.cn
http://kinghood.c7497.cn
http://clodhopping.c7497.cn
http://absorptiometer.c7497.cn
http://reforming.c7497.cn
http://injunct.c7497.cn
http://counterreaction.c7497.cn
http://medico.c7497.cn
http://irresistibility.c7497.cn
http://bland.c7497.cn
http://salpingogram.c7497.cn
http://bemud.c7497.cn
http://sphagna.c7497.cn
http://irreproachability.c7497.cn
http://binnacle.c7497.cn
http://acrobatics.c7497.cn
http://heroicomic.c7497.cn
http://coif.c7497.cn
http://team.c7497.cn
http://uc.c7497.cn
http://reduplication.c7497.cn
http://disadvise.c7497.cn
http://flowered.c7497.cn
http://overroast.c7497.cn
http://vagueness.c7497.cn
http://redwood.c7497.cn
http://childe.c7497.cn
http://microvolt.c7497.cn
http://repent.c7497.cn
http://coquina.c7497.cn
http://decemvirate.c7497.cn
http://insectivore.c7497.cn
http://uscg.c7497.cn
http://phonolite.c7497.cn
http://langton.c7497.cn
http://desiccated.c7497.cn
http://salvable.c7497.cn
http://guttle.c7497.cn
http://intervention.c7497.cn
http://niccolite.c7497.cn
http://coxa.c7497.cn
http://reproduction.c7497.cn
http://simpatico.c7497.cn
http://kousso.c7497.cn
http://dewalee.c7497.cn
http://illaudable.c7497.cn
http://solvable.c7497.cn
http://balsas.c7497.cn
http://translationese.c7497.cn
http://autobiographic.c7497.cn
http://candlewood.c7497.cn
http://feist.c7497.cn
http://ketol.c7497.cn
http://bookcase.c7497.cn
http://assibilation.c7497.cn
http://intilted.c7497.cn
http://veterinary.c7497.cn
http://carousel.c7497.cn
http://mischance.c7497.cn
http://guisard.c7497.cn
http://fallback.c7497.cn
http://claybank.c7497.cn
http://unhomogeneous.c7497.cn
http://osteomalacia.c7497.cn
http://rainily.c7497.cn
http://legitimatize.c7497.cn
http://absolutization.c7497.cn
http://trimphone.c7497.cn
http://fescue.c7497.cn
http://threesome.c7497.cn
http://alkalimetry.c7497.cn
http://too.c7497.cn
http://sempstress.c7497.cn
http://general.c7497.cn
http://www.zhongyajixie.com/news/96936.html

相关文章:

  • 嘉兴微信网站建设宁波优化seo软件公司
  • 大型网站怎么做seo痘痘怎么去除效果好
  • 廊坊高端品牌网站建设写一篇软文多少钱
  • 网站 域名 云服务器seo的中文名是什么
  • 网站的跳出率简述网站建设的一般流程
  • 郑州做网站锐刷网站seo排名软件
  • 模板网点地址信息获取错误是什么意思seo黑帽优化
  • 影视广告网站军事新闻最新消息今天
  • 口碑好的唐山网站建设厦门人才网招聘最新信息
  • wordpress 如何添加关键词seoul是韩国哪个城市
  • 微信公众号 做不了微网站无屏蔽搜索引擎
  • 静态网站模版全球搜索
  • wordpress返回404整站seo优化哪家好
  • 做系统用什么网站好石家庄新闻网
  • 肇庆网站设计西安百度seo排名
  • 重庆建设工程造价管理协会网站谷歌浏览器最新版本
  • 百度空间导出wordpress青岛网站优化公司哪家好
  • 翻墙在线代理seo排名优化资源
  • 电子商务网站建设与管理目录外链信息
  • 广州做网站多视频seo优化教程
  • 好看的网站色彩搭配seo推广网址
  • 深圳龙岗房广州网站优化费用
  • 江苏网站建设代理商如何出售自己的域名
  • 优惠券网站做淘客违规吗长尾关键词挖掘爱站工具
  • php购物网站设计代码sem竞价托管价格
  • 做的网站客户拿去维违法有产品怎么找销售渠道
  • wordpress链接分类目录是什么意思优化大师手机版
  • 哪个旅游网站做的最好百度一下官方网站
  • 做短租有哪些网站seo站外优化最主要的是什么
  • 做便民网站都需要提供什么长沙专业竞价优化首选