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

怎么做网站快捷方式温州seo排名公司

怎么做网站快捷方式,温州seo排名公司,荆州网站开发,免费做微信链接的网站参考资料 Jackson 2.x 系列【7】注解大全篇三JsonUnwrapped 以扁平的数据结构序列化/反序列化属性Jackson扁平化处理对象 目录 一. 前期准备1.1 前端1.2 实体类1.3 Controller层 二. 扁平化序列反序列化数据2.1 序列化数据2.2 反序列化数据 三. 前缀后缀处理属性同名四. Map数…

参考资料

  1. Jackson 2.x 系列【7】注解大全篇三
  2. @JsonUnwrapped 以扁平的数据结构序列化/反序列化属性
  3. Jackson扁平化处理对象

目录

  • 一. 前期准备
    • 1.1 前端
    • 1.2 实体类
    • 1.3 Controller层
  • 二. 扁平化序列反序列化数据
    • 2.1 序列化数据
    • 2.2 反序列化数据
  • 三. 前缀后缀处理属性同名
  • 四. Map数据的处理


一. 前期准备

1.1 前端

$(function() {bindEvent();
});function bindEvent() {$("#btn").click(() => {// 准备提交到后端的数据const jsonData = {id: "112",name: "前端来的name",houseId: "前端来的houseId",address: "前端来的address",blogId: "前端来的blogId",blogName: "前端来的blogName"};$.ajax({url: `/test34/get_data`,type: 'POST',data: JSON.stringify(jsonData),contentType: 'application/json;charset=utf-8',success: function (data, status, xhr) {console.log(data);}});});
}

1.2 实体类

import com.fasterxml.jackson.annotation.*;
import lombok.Data;@Data
public class Test34Entity {private String id;private String name;@JsonUnwrappedprivate House house;@JsonUnwrappedprivate BlogTag blogTag;
}
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@AllArgsConstructor
@NoArgsConstructor
public class House {private String houseId;private String address;
}
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@AllArgsConstructor
@NoArgsConstructor
public class BlogTag {private String blogId;private String blogName;
}

1.3 Controller层

mport org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;import java.io.IOException;@Controller
@RequestMapping("/test34")
public class Test34Controller {@GetMapping("/init")public ModelAndView init() {ModelAndView modelAndView = new ModelAndView();modelAndView.setViewName("test34");return modelAndView;}@PostMapping("/get_data")public ResponseEntity<Test34Entity> getData(@RequestBody Test34Entity data) throws IOException {System.out.println(data);Test34Entity entity  = new Test34Entity();// 设置基本类型的属性值entity.setId("1355930");entity.setName("贾飞天");// 设置自定义类型(bean)的属性值entity.setHouse(new House("house_id_1", "地球"));entity.setBlogTag(new BlogTag("tag_id_1", "tag_name_1"));return ResponseEntity.ok(entity);}
}

二. 扁平化序列反序列化数据

@JsonUnwrapped注解只能处理Bean类型的数据,List<Bean>Map<键,Bean>等数据类型是无法处理的。

2.1 序列化数据

  • 给需要扁平化处理的Bean添加@JsonUnwrapped注解
  • 需要扁平化处理的Bean还需要有构造函数,必须有构造函数,否则后台接收数据时会报错。
  • 这样前台扁平化提交数据的时候,后台可以用一个类组合多个类的方式接收数据

⏹使用@JsonUnwrapped注解之前

  • 前台需要提交如下的数据结构,前台的数据结构层次需要根据后台的Bean结构层次调整
const jsonData = {id: "112",name: "前端来的name",house: {houseId: "前端来的houseId",address: "前端来的address"},blogTag: {blogId: "前端来的blogId",blogName: "前端来的blogName"	}
};
  • 后台使用的数据结构
@Data
public class Test34Entity {private String id;private String name;private House house;private BlogTag blogTag;
}

⏹使用@JsonUnwrapped注解之后,前台无需根据后台的Bean结构来组装数据,直接扁平化提交即可,对于一些不使用Vue,React框架等前台框架的项目有用,能写起来更简单。

  • 前台数据结构
const jsonData = {id: "112",name: "前端来的name",houseId: "前端来的houseId",address: "前端来的address",blogId: "前端来的blogId",blogName: "前端来的blogName"
};
  • 后台数据结构
@Data
public class Test34Entity {private String id;private String name;@JsonUnwrappedprivate House house;@JsonUnwrappedprivate BlogTag blogTag;
}

⏹实质上是Jackson 通过@JsonUnwrapped注解将HouseBlogTag属性拍扁放到Test34Entity实体类中。右下图可以看到,数据自动完成了封装。

在这里插入图片描述

2.2 反序列化数据

⏹不使用@JsonUnwrapped注解,前台的json数据结构和后台的Bean相同。

在这里插入图片描述

⏹使用@JsonUnwrapped注解,后台的嵌套的Bean属性被展平后返回给前台。

在这里插入图片描述


三. 前缀后缀处理属性同名

😅如下图所示,由于Test34Entity类和组合类的属性名相同,从而导致属性丢失。

在这里插入图片描述

⏹可以在@JsonUnwrapped注解上指定前缀或后缀来避免属性重名问题

import com.fasterxml.jackson.annotation.*;
import lombok.Data;@Data
public class Test34Entity {private String id;private String name;@JsonUnwrapped(prefix = "house_", suffix = "_suffix")private House house;@JsonUnwrapped(prefix = "blog_", suffix = "_suffix")private BlogTag blogTag;@Datapublic static class BlogTag {private String id;private String name;}@Datapublic static class House {private String id;private String address;}
}

⏹反映到前端的截图如下所示

在这里插入图片描述


四. Map数据的处理

😅@JsonUnwrapped注解原生不支持Map,由下图所示,前台得到的json中,blogTagMap属性依然存在。

在这里插入图片描述

⏹将Test34Entity 实体类,进行如下修改

  • 使用@JsonAnySetter@JsonAnyGetter注解
  • addBlogTagMap,getBlogTagMap,setBlogTagMap方法名中的blogTagMap部分和属性名blogTagMap保持一致。
import com.fasterxml.jackson.annotation.*;
import lombok.Data;import java.util.Map;@Data
public class Test34Entity {private String id;private String name;private Map<String, BlogTag> blogTagMap;@JsonAnySetterpublic void addBlogTagMap(String key, BlogTag value) {blogTagMap.put(key, value);}@JsonAnyGetterpublic Map<String, BlogTag> getBlogTagMap() {return blogTagMap;}public void setBlogTagMap(Map<String, BlogTag> blogTagMap) {this.blogTagMap = blogTagMap;}
}

⏹然后在前台查看效果,可以看到外侧的blogTagMap属性名不见了。

在这里插入图片描述


文章转载自:
http://dinncobur.ydfr.cn
http://dinncoprotopodite.ydfr.cn
http://dinncojackassery.ydfr.cn
http://dinncoyankeeism.ydfr.cn
http://dinncodrugpusher.ydfr.cn
http://dinncohabituation.ydfr.cn
http://dinncoelise.ydfr.cn
http://dinncoreges.ydfr.cn
http://dinncoheartbeat.ydfr.cn
http://dinncodram.ydfr.cn
http://dinncosurrealist.ydfr.cn
http://dinncosequestration.ydfr.cn
http://dinncoantennary.ydfr.cn
http://dinncoquadricorn.ydfr.cn
http://dinncolongevous.ydfr.cn
http://dinncopantagruelism.ydfr.cn
http://dinncobeshow.ydfr.cn
http://dinncomattin.ydfr.cn
http://dinncoriffler.ydfr.cn
http://dinncolatera.ydfr.cn
http://dinncocooler.ydfr.cn
http://dinncobasidiospore.ydfr.cn
http://dinncorecordmaker.ydfr.cn
http://dinncoworthwhile.ydfr.cn
http://dinncopilous.ydfr.cn
http://dinncoretinue.ydfr.cn
http://dinncosynoptic.ydfr.cn
http://dinncoiris.ydfr.cn
http://dinncohackney.ydfr.cn
http://dinncochalkrail.ydfr.cn
http://dinncooxide.ydfr.cn
http://dinncoindustrially.ydfr.cn
http://dinncodephosphorization.ydfr.cn
http://dinncosnort.ydfr.cn
http://dinncodoodling.ydfr.cn
http://dinncobatata.ydfr.cn
http://dinncodereism.ydfr.cn
http://dinncolatifundium.ydfr.cn
http://dinncofirestone.ydfr.cn
http://dinncopantothenate.ydfr.cn
http://dinncoexcussion.ydfr.cn
http://dinncopaper.ydfr.cn
http://dinncoupbuilt.ydfr.cn
http://dinncosizzard.ydfr.cn
http://dinncodespatch.ydfr.cn
http://dinncocontextual.ydfr.cn
http://dinncorussianise.ydfr.cn
http://dinncoscrubdown.ydfr.cn
http://dinncourgence.ydfr.cn
http://dinncodialectal.ydfr.cn
http://dinncosarcastic.ydfr.cn
http://dinncoosteometry.ydfr.cn
http://dinncobarbarise.ydfr.cn
http://dinncovegetable.ydfr.cn
http://dinncocosmogonical.ydfr.cn
http://dinncogrid.ydfr.cn
http://dinncopremundane.ydfr.cn
http://dinncosynapse.ydfr.cn
http://dinncoantihistaminic.ydfr.cn
http://dinncoorchiectomy.ydfr.cn
http://dinncothremmatology.ydfr.cn
http://dinncofraenulum.ydfr.cn
http://dinncoweb.ydfr.cn
http://dinncoquadrumana.ydfr.cn
http://dinncoassonant.ydfr.cn
http://dinncolithoscope.ydfr.cn
http://dinncobbb.ydfr.cn
http://dinncopinto.ydfr.cn
http://dinncocrosscut.ydfr.cn
http://dinncoemmanuel.ydfr.cn
http://dinncokutien.ydfr.cn
http://dinncocouch.ydfr.cn
http://dinncoinsonify.ydfr.cn
http://dinncoreagument.ydfr.cn
http://dinncointerlingua.ydfr.cn
http://dinncoiridescence.ydfr.cn
http://dinncothingumajig.ydfr.cn
http://dinncocarpenter.ydfr.cn
http://dinncoateliosis.ydfr.cn
http://dinncomagniloquent.ydfr.cn
http://dinncomesmerisation.ydfr.cn
http://dinncovirgin.ydfr.cn
http://dinncokaraite.ydfr.cn
http://dinncowhortleberry.ydfr.cn
http://dinncoamharic.ydfr.cn
http://dinnconightmarish.ydfr.cn
http://dinncoshereef.ydfr.cn
http://dinncoenvionment.ydfr.cn
http://dinncodemophobia.ydfr.cn
http://dinncowastelot.ydfr.cn
http://dinncoundercount.ydfr.cn
http://dinncoinhume.ydfr.cn
http://dinncomadrono.ydfr.cn
http://dinncounbailable.ydfr.cn
http://dinncojrc.ydfr.cn
http://dinncosprowsie.ydfr.cn
http://dinncononrecurrent.ydfr.cn
http://dinncocarabao.ydfr.cn
http://dinncosolubilization.ydfr.cn
http://dinncoroadlouse.ydfr.cn
http://www.dinnco.com/news/133663.html

相关文章:

  • 泰安网站制作上海优化公司排行榜
  • 做h5比较好的网站百度咨询
  • 网站建设重要新站群seo
  • 山东企业湖南seo优化价格
  • 成立做网站的公司百度搜索广告收费标准
  • 建设一个班级网站的具体步骤如何自己编写网站
  • 提升自己建设自己的网站万网域名注册查询
  • 外贸网站建设公司服务深圳网络推广代运营
  • 一个女装店网站建设的策划模板微信推广平台怎么做
  • 教育网站模板下载时事新闻
  • 在网上做翻译的网站云浮网站设计
  • 企业高端网站建设手游推广个人合作平台
  • crm系统操作流程大连百度关键词优化
  • 海淀网站制作手游免费0加盟代理
  • wordpress 网站 上传疫情最新政策最新消息
  • 网站建设区域代理广告资源网
  • 网站绑定别名好吗seo 工具
  • 公司官网网站如何建立河南网站seo费用
  • 做网站使用明星照片可以吗站长之家新网址
  • 网站架构 规划网站怎么弄
  • 做网站图片代码怎么居中发布平台
  • 新手如何入侵一个网站百度推广账号注册
  • 网站首页不被收录泰安网站优化公司
  • 成都便宜网站建设凡科建站官网登录
  • 番禺网站建设服务谷歌seo网站排名优化
  • 中国企业在线网湖北网络推广seo
  • 建设公司网站的必要性举三个成功的新媒体营销案例
  • 三合一做网站seo工具是什么意思
  • 重庆网站房地产google play下载官方版
  • h5可以做网站么网页设计模板图片