91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java前后端分離使用注解優雅的返回實體部分屬性

發布時間:2020-07-25 10:18:30 來源:網絡 閱讀:333 作者:ckllf 欄目:編程語言


  #第一個注解

  import java.lang.annotation.ElementType;

  import java.lang.annotation.Retention;

  import java.lang.annotation.RetentionPolicy;

  import java.lang.annotation.Target;

  /**

  * @Description:

  * @Author: ckk

  * @CreateDate: 2019/9/17 17:15

  */

  @Target({ElementType.METHOD})

  @Retention(RetentionPolicy.RUNTIME)

  public @interface JSONS {

  JSONField[] value();

  }

  #第二個注解

  import java.lang.annotation.*;

  /**

  * @Description:

  * @Author: ckk

  * @CreateDate: 2019/9/17 17:16

  */

  @Target({ElementType.METHOD})

  @Retention(RetentionPolicy.RUNTIME)

  @Repeatable(JSONS.class)

  public @interface JSONField {

  Class type();

  String[] include() default {""};

  String[] filter() default {""};

  }

  #解析器

  import com.fasterxml.jackson.annotation.JsonFilter;

  import com.fasterxml.jackson.core.JsonGenerator;

  import com.fasterxml.jackson.databind.SerializerProvider;

  import com.fasterxml.jackson.databind.ser.BeanPropertyFilter;

  import com.fasterxml.jackson.databind.ser.FilterProvider;

  import com.fasterxml.jackson.databind.ser.PropertyFilter;

  import com.fasterxml.jackson.databind.ser.PropertyWriter;

  import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;

  import java.util.*;

  /**

  * @Description:

  * @Author: ckk

  * @CreateDate: 2019/9/17 17:19

  */

  @JsonFilter("JacksonFilter")

  public class JacksonJsonFilter extends FilterProvider {

  Map, Set> includeMap = new HashMap();

  Map, Set> filterMap = new HashMap();

  public JacksonJsonFilter() {

  }

  public void include(Class type, String[] fields) {

  this.addToMap(this.includeMap, type, fields);

  }

  public void filter(Class type, String[] fields) {

  this.addToMap(this.filterMap, type, fields);

  }

  private void addToMap(Map, Set> map, Class type, String[] fields) {

  Set fieldSet = (Set) map.getOrDefault(type, new HashSet());

  fieldSet.addAll(Arrays.asList(fields));

  map.put(type, fieldSet);

  }

  public BeanPropertyFilter findFilter(Object filterId) {

  throw new UnsupportedOperationException("Access to deprecated filters not supported");

  }

  public PropertyFilter findPropertyFilter(Object filterId, Object valueToFilter) {

  return new SimpleBeanPropertyFilter() {

  public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider prov, PropertyWriter writer) throws Exception {

  if (JacksonJsonFilter.this.apply(pojo.getClass(), writer.getName())) {

  writer.serializeAsField(pojo, jgen, prov);

  } else if (!jgen.canOmitFields()) {

  writer.serializeAsOmittedField(pojo, jgen, prov);

  }

  }

  };

  }

  public boolean apply(Class type, String name) {

  Set includeFields = (Set) this.includeMap.get(type);

  Set filterFields = (Set) this.filterMap.get(type);

  if (includeFields != null && includeFields.contains(name)) {

  return true;

  } else if (filterFields != null && !filterFields.contains(name)) {

  return true;

  } else {

  return includeFields == null && filterFields == null;

  }

  }

  }

  序列化器

  import com.fasterxml.jackson.core.JsonProcessingException;

  import com.fasterxml.jackson.databind.ObjectMapper;

  import org.apache.commons.lang3.StringUtils;

  /**

  * @Description:

  * @Author: ckk

  * @CreateDate: 2019/9/17 17:18

  */無錫做人流手術多少錢 http://www.ytsg029.com/

  public class CustomerJsonSerializer {

  ObjectMapper mapper = new ObjectMapper();

  JacksonJsonFilter jacksonFilter = new JacksonJsonFilter();

  public CustomerJsonSerializer() {

  }

  public void filter(Class clazz, String[] include, String[] filter) {

  if (clazz != null) {

  if (include.length > 1 || include.length == 1 && org.apache.commons.lang3.StringUtils.isNotBlank(include[0])) {

  this.jacksonFilter.include(clazz, include);

  }

  if (filter.length > 1 || filter.length == 1 && StringUtils.isNotBlank(filter[0])) {

  this.jacksonFilter.filter(clazz, filter);

  }

  this.mapper.addMixIn(clazz, this.jacksonFilter.getClass());

  }

  }

  public String toJson(Object object) throws JsonProcessingException {

  this.mapper.setFilterProvider(this.jacksonFilter);

  return this.mapper.writeValueAsString(object);

  }

  public void filter(JSONField json) {

  this.filter(json.type(), json.include(), json.filter());

  }

  }

  #使用方法

  @ApiOperation(value = “查詢詳情”, response = ZcPolicyVo.class)

  @GetMapping(“getById/{id}”)

  @JSONS({@JSONField(type = ZcPolicyVo.class, filter = {“base_id”, “pic”, “mobilecontent”,

  “synchtime”, “url”, “policy_originid”, “base_updatetime”, “tags”, “audittime”, “creator”}),

  @JSONField(type = SysAreaVo.class, include = {“base_id”, “base_name”}),

  @JSONField(type = SysCodeVo.class, include = {“base_id”, “base_name”}),

  @JSONField(type = ZcRelationVo.class, include = {“keyId”, “keyIdName”}),

  @JSONField(type = ImUsersVo.class, include = {“userid”, “username”}),

  @JSONField(type = ZcCentraldeptcodeVo.class, include = {“codeId”, “codeIdName”}),

  @JSONField(type = ZcLocaldeptcodeVo.class, include = {“codeId”, “codeIdName”}),

  @JSONField(type = PolicyKeywordsVo.class, include = {“keyId”, “keyIdName”}),

  @JSONField(type = PolicyMapKeywordsVo.class, include = {“keyId”, “keyIdName”}),

  @JSONField(type = ZcKeywordVo.class, include = {“baseId”, “title”})

  })

  public Message getById(@PathVariable(“id”) String id) {

  try {

  ZcPolicy zcPolicy = zcPolicyJpaService.getObjectByPK(id);

  return Message.success(BeanutilsCopy.convertBean(zcPolicy, ZcPolicyVo.class));

  } catch (Exception e) {

  logger.error("查詢詳情異常:===》 " + e);

  return Message.exception(e.getMessage());

  }

  }

  #filter:排除某些屬性

  #include :包括某些屬性


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宜宾市| 锡林郭勒盟| 旬阳县| 黄石市| 林州市| 石台县| 广宁县| 锡林郭勒盟| 饶阳县| 巴东县| 和林格尔县| 华池县| 平潭县| 清水县| 鄂州市| 汕尾市| 楚雄市| 阿图什市| 磐安县| 澄迈县| 崇明县| 凤冈县| 巴里| 远安县| 长宁县| 江口县| 玉林市| 安丘市| 安岳县| 马山县| 莱州市| 海林市| 庆城县| 荣成市| 隆林| 武定县| 寻乌县| 马边| 慈利县| 阿勒泰市| 祁阳县|