zoukankan      html  css  js  c++  java
  • spring boot jackson 时间转换

    Entity

    @Data
    public class ExampleLeave  implements Serializable {
        private String id;
        private String title;
        private String leaveType;
        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
        private Date startDate;
        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
        private Date endDate;
        private BigDecimal count;
        private String reason;
        private int status;
    }

    工具类

    public class JsonResult implements Serializable {
      
    
        public static <T> T convertValue(String content, Class<T> toValueType ) {
            ObjectMapper mapper = objectMapper();
            mapper.setDateFormat(new SimpleDateFormat(DateFormat.DEFAULT_PATTERN.getValue()));
            try {
                return mapper.readValue(content, toValueType);
            } catch (IOException e) {
                e.printStackTrace();
                log.error(e.toString());
                return null;
            }
        }
        private static ObjectMapper objectMapper(){
            ObjectMapper mapper = new ObjectMapper();
            mapper.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
            return mapper;
        }
    }

    Controller

        @RequestMapping(value = "/save", method = RequestMethod.POST)
        @ResponseBody
        public void save(String  leave) {
           ExampleLeave exampleLeave= JsonResult.convertValue(leave,ExampleLeave.class);
        }
  • 相关阅读:
    tp5的 LayUI分页样式实现
    BSBuDeJie_05
    WCF 程序入门
    iOS Xcode 调试技巧
    Visual Studio 2015 如何将全英界面转成中文
    BSBuDeJie_04
    BSBuDeJie_03
    BSBuDeJie_02
    BSBuDeJie_01
    iOS 一些琐碎的知识点
  • 原文地址:https://www.cnblogs.com/xinting/p/12536128.html
Copyright © 2011-2022 走看看