{"id":9911,"date":"2023-03-15T14:25:25","date_gmt":"2023-03-15T06:25:25","guid":{"rendered":"http:\/\/123.57.164.21\/?p=9911"},"modified":"2023-03-15T14:25:25","modified_gmt":"2023-03-15T06:25:25","slug":"springboot-%e6%8e%a5%e5%8f%a3%e6%8e%a5%e6%94%b6%e6%95%b4%e6%95%b0%e5%9e%8b%e5%ad%97%e6%ae%b5%e4%bc%a0%e5%b0%8f%e6%95%b0%e4%b8%8d%e6%8a%a5%e9%94%99","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=9911","title":{"rendered":"Springboot \u63a5\u53e3\u63a5\u6536\u6574\u6570\u578b\u5b57\u6bb5\u4f20\u5c0f\u6570\u4e0d\u62a5\u9519"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">\u95ee\u9898\uff1aspringboot\u63a5\u53e3\u63a5\u6536Long\u6216Integer\u8fd9\u79cd\u6574\u6570\u578b\u5b57\u6bb5\uff0c\u5982\u679c\u4f20\u5c0f\u6570\u4e0d\u62a5\u9519\uff0c\u4f1a\u53ea\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002\n\u89e3\u51b3\u65b9\u6848\uff1aspringboot\u9ed8\u8ba4\u91c7\u7528jackson\u8fdb\u884c\u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\uff0c\u6dfb\u52a0jackson\u5bf9\u6574\u6570\u7c7b\u578b\u7684\u53cd\u5e8f\u5217\u5316\u3002\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package com.example.demo.config;\n\nimport com.fasterxml.jackson.core.JsonParser;\nimport com.fasterxml.jackson.databind.*;\nimport com.fasterxml.jackson.databind.module.SimpleModule;\nimport com.fasterxml.jackson.module.paramnames.ParameterNamesModule;\nimport org.springframework.beans.factory.annotation.Qualifier;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\nimport java.io.IOException;\nimport java.time.format.DateTimeFormatter;\n\n@Configuration\npublic class JacksonConfiguration {\n\n    @Value(\"${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}\")\n    private String formatValue;\n\n    @Bean(name = \"format\")\n    public DateTimeFormatter format() {\n        return DateTimeFormatter.ofPattern(formatValue);\n    }\n\n    @Bean\n    public ObjectMapper serializingObjectMapper(@Qualifier(\"format\") DateTimeFormatter format) {\n        ObjectMapper mapper = new ObjectMapper()\n                .registerModule(new ParameterNamesModule())\n                .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)\n                .disable(MapperFeature.DEFAULT_VIEW_INCLUSION)\n                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)\n                .registerModule(serializerAndDeserializerModule());\n        return mapper;\n    }\n\n    \/**\n     * \u5e8f\u5217\u5316\u4e0e\u53cd\u5e8f\u5217\u5316\n     * @return SimpleModule\n     *\/\n    public SimpleModule serializerAndDeserializerModule(){\n        SimpleModule module = new SimpleModule();\n\n        module.addDeserializer(Long.class, LongJsonDeserializer.instance);\n        module.addDeserializer(Long.TYPE, LongJsonDeserializer.instance);\n\n        module.addDeserializer(Integer.class, IntegerJsonDeserializer.instance);\n        module.addDeserializer(Integer.TYPE, IntegerJsonDeserializer.instance);\n\n        return module;\n    }\n\n    public static class LongJsonDeserializer extends JsonDeserializer&lt;Long> {\n        public static final LongJsonDeserializer instance = new LongJsonDeserializer();\n        @Override\n        public Long deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {\n            String value = jsonParser.getText();\n            try {\n                return value == null ? null : Long.parseLong(value);\n            } catch (NumberFormatException e) {\n                throw e;\n            }\n        }\n    }\n\n    public static class IntegerJsonDeserializer extends JsonDeserializer&lt;Integer> {\n        public static final IntegerJsonDeserializer instance = new IntegerJsonDeserializer();\n        @Override\n        public Integer deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {\n            String value = jsonParser.getText();\n            try {\n                return value == null ? null : Integer.parseInt(value);\n            } catch (NumberFormatException e) {\n                throw e;\n            }\n        }\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\uff1aspringboot\u63a5\u53e3\u63a5\u6536Long\u6216Integer\u8fd9\u79cd\u6574\u6570\u578b\u5b57\u6bb5\uff0c\u5982\u679c\u4f20\u5c0f\u6570\u4e0d\u62a5\u9519\uff0c\u4f1a\u53ea\u4fdd\u7559\u6574\u6570\u90e8\u5206\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9911"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9911"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9911\/revisions"}],"predecessor-version":[{"id":9912,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/9911\/revisions\/9912"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}