{"id":12847,"date":"2023-09-27T21:29:36","date_gmt":"2023-09-27T13:29:36","guid":{"rendered":"https:\/\/92it.top\/?p=12847"},"modified":"2023-09-27T21:29:36","modified_gmt":"2023-09-27T13:29:36","slug":"springboot-httpmessageconverters-json%e6%a0%bc%e5%bc%8f%e5%8c%96","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=12847","title":{"rendered":"SpringBoot HttpMessageConverters JSON\u683c\u5f0f\u5316"},"content":{"rendered":"\n<p><strong>\u524d\u8a00<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>SpringBoot\u4e25\u683c\u7684\u6765\u8bf4\uff0c\u5e94\u8be5\u662f\u4e00\u79cd\u8d1f\u8d23\u628a\u5176\u4ed6\u5df2\u6709\u6846\u67b6\u6574\u5408\u5728\u4e00\u8d77\u7684\u5de5\u5177\uff0cSpringBoot\u4e3b\u8981\u662f\u628a\u5404\u79cd\u6846\u67b6\u90fd\u6574\u5408\u96c6\u4e2d\u5728\u4e00\u8d77\uff0c\u7b80\u5316\u6211\u4eec\u7684Web\u5f00\u53d1\u3002\u6240\u4ee5\u5f88\u591a\u7684\u529f\u80fd\uff0c\u5176\u5b9e\u90fd\u4e0d\u662fSpringBoot\u5b8c\u6210\u7684\uff0c\u800c\u662f\u7531SpringBoot\u4e2d\u6574\u5408\u7684\u5176\u4ed6\u6846\u67b6\u6765\u5b8c\u6210\u7684\u3002\u6bd4\u5982Web\u5f00\u53d1\uff0c\u66f4\u591a\u7684\u662f\u7531SpringMVC\u6765\u5b8c\u6210\uff0c\u53ea\u662fSpringBoot\u5f88\u597d\u7684\u628aSpringMVC\u6574\u5408\u4e86\u8fdb\u6765\uff0c\u800c\u4e14\u5bf9SpringMVC\u7684\u5b9a\u5236\u5316\u5f00\u53d1\u4e5f\u63d0\u4f9b\u4e86\u5f88\u591a\u4fbf\u5229\u3002<\/p>\n\n\n\n<p>\u672c\u6587\u4f1a\u7ed9\u5927\u5bb6\u8bb2\u89e3SpringBoot\u4e2d\u662f\u5982\u4f55\u5bf9SpringMVC\u8fdb\u884c\u6574\u5408\u652f\u6301\u7684\uff0c\u4ee5\u6b64\u4e3a\u6211\u4eec\u4ee5\u540e\u5b66\u4e60\u5176\u4ed6\u6846\u67b6\u7684\u6574\u5408\u63d0\u4f9b\u501f\u9274\u601d\u8def\u3002<\/p>\n\n\n\n<p><strong>\u4e00. SpringMVC\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Spring Boot\u4e2d\u5185\u5d4c\u4e86Tomcat\uff0cJetty\u6216Undertow\u7b49\u670d\u52a1\u5668\uff0c\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u975e\u5e38\u8f7b\u677e\u7684\u521b\u5efa\u51fa\u4e00\u4e2aHTTP\u670d\u52a1\u5668\uff0c\u800c\u5927\u591a\u6570\u7684web\u5e94\u7528\u90fd\u53ef\u4ee5\u4f7f\u7528spring-boot-starter-web\u6a21\u5757\u8fdb\u884c\u5feb\u901f\u642d\u5efa\u548c\u8fd0\u884c\uff0cWeb\u6a21\u5757\u7684\u5f00\u53d1\u4e3b\u8981\u662f\u57fa\u4e8eSpringMVC\u6846\u67b6\u6765\u8fdb\u884c\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p><strong>1. SpringMVC\u6982\u5ff5<\/strong><\/p>\n\n\n\n<p>SpringMVC\u6846\u67b6\u662f\u4e00\u4e2a\u201c\u6a21\u578b\uff0c\u89c6\u56fe\uff0c\u63a7\u5236\u5668\u201d\u7684Web\u6846\u67b6\uff0c\u5141\u8bb8\u7528\u6237\u521b\u5efa\u7279\u5b9a\u7684@Controller\u6216@RestController\u7c7b\uff0c\u6765\u5904\u7406\u4f20\u5165\u7684HTTP\u8bf7\u6c42\uff0c\u901a\u8fc7@RequestMapping\u6ce8\u89e3\u53ef\u4ee5\u5c06\u63a7\u5236\u5668\u4e2d\u7684\u65b9\u6cd5\u6620\u5c04\u5230\u76f8\u5e94\u7684HTTP\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p><strong>2. SpringMVC\u7684\u81ea\u52a8\u914d\u7f6e\u7279\u6027<\/strong><\/p>\n\n\n\n<p>Spring Boot\u4e3aSpring MVC\u63d0\u4f9b\u7684auto-configuration\u7279\u6027\u9002\u7528\u4e8e\u5927\u591a\u6570\u5e94\u7528\uff0c\u5e76\u5728Spring\u9ed8\u8ba4\u529f\u80fd\u4e0a\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n\n\n\n<ul><li>\u5f15\u5165ContentNegotiatingViewResolver\u548cBeanNameViewResolver beans\u3002<\/li><li>\u5bf9\u9759\u6001\u8d44\u6e90\u7684\u652f\u6301\uff0c\u5305\u62ec\u5bf9WebJars\u7684\u652f\u6301\u3002<\/li><li>\u81ea\u52a8\u6ce8\u518cConverter\uff0cGenericConverter\uff0cFormatter beans\u3002<\/li><li>\u5bf9HttpMessageConverters\u7684\u652f\u6301\uff0c\u8d1f\u8d23Http\u4fe1\u606f\u8f6c\u6362\u3002<\/li><li>\u81ea\u52a8\u6ce8\u518cMessageCodeResolver\u3002<\/li><li>\u5bf9\u9759\u6001index.html\u7684\u652f\u6301\u3002<\/li><li>\u5bf9\u81ea\u5b9a\u4e49Favicon\u7684\u652f\u6301\u3002<\/li><li>\u81ea\u52a8\u4f7f\u7528ConfigurableWebBindingInitializer bean\u3002<\/li><li>\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5df1\u7684WebMvcConfigurerAdapter\u7c7b\u578b\u7684@Configuration\u7c7b\uff0c\u800c\u4e0d\u9700\u8981@EnableWebMvc\u6ce8\u89e3\uff1b\u4e5f\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684HttpMessageConverters\u5b9e\u73b0JSON\u3001XML\u4fe1\u606f\u7684\u81ea\u5b9a\u4e49\u8f6c\u6362\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u4e8c. HttpMessageConverter\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>1. \u6982\u8ff0<\/strong><\/p>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u8fdb\u884cWeb\u5f00\u53d1\uff0c\u4e00\u822c\u90fd\u8981\u8bbe\u8ba1\u6210RESTful\u98ce\u683c\u7684API\uff0c\u901a\u8fc7JSON\u683c\u5f0f\u7684\u6570\u636e\u8fdb\u884c\u4ea4\u4e92\u3002\u4f46\u662f\u524d\u7aef\u4f20\u5165\u7684 JSON \u6570\u636e\u5230\u5e95\u662f\u5982\u4f55\u88ab\u89e3\u6790\u6210 Java \u5bf9\u8c61\u4f5c\u4e3a API\u5165\u53c2\u7684\uff0c\u540e\u7aef\u8fd4\u56de\u7684\u7ed3\u679c\u53c8\u662f\u5982\u4f55\u628a Java \u5bf9\u8c61\u89e3\u6790\u6210 JSON \u683c\u5f0f\u7684\u6570\u636e\u8fd4\u56de\u7ed9\u524d\u7aef\u7684\uff0c\u5728\u6574\u4e2a\u6570\u636e\u6d41\u8f6c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u8fd9\u4e9b\u5de5\u4f5c\u90fd\u662f\u7531\u8c01\u6765\u5b8c\u6210\u7684\u5462\uff1f<\/p>\n\n\n\n<p>\u5176\u5b9e\u8fd9\u90fd\u662f\u7531HttpMessageConverter\u8d77\u5230\u7684\u4f5c\u7528\uff01<\/p>\n\n\n\n<p><strong>2. HttpMessageConverter\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<p>org.springframework.http.converter.HttpMessageConverter \u662fSpringMVC\u4e2d\u63d0\u4f9b\u7684\u4e00\u4e2a\u7b56\u7565\u63a5\u53e3\uff0c\u5b83\u662f\u4e00\u4e2a\u8f6c\u6362\u5668\u7c7b\uff0c\u8d1f\u8d23\u8f6c\u6362HTTP\u7684\u8bf7\u6c42\u548c\u54cd\u5e94\uff0c\u53ef\u4ee5\u628a\u5bf9\u8c61\u81ea\u52a8\u8f6c\u6362\u4e3aJSON(\u4f7f\u7528Jackson\u5e93\u6216Gson\u5e93)\u6216XML(\u4f7f\u7528Jackson XML\u6216\u8005JAXB2)\uff0c\u5bf9\u5b57\u7b26\u4e32\u9ed8\u8ba4\u4f7f\u7528UTF-8\u7f16\u7801\u5904\u7406\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u6211\u4eec\u91c7\u7528\u9ed8\u8ba4\u914d\u7f6e\u5c31\u53ef\u4ee5\u3002<\/p>\n\n\n\n<p>\u8be5\u63a5\u53e3\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>Strategy interface that specifies a converter that can convert from and to HTTP requests and responses\u3002<\/p>\n\n\n\n<p>\u7b80\u5355\u8bf4\u5c31\u662f HTTP request(\u8bf7\u6c42)\u548cresponse(\u54cd\u5e94)\u7684\u8f6c\u6362\u5668\u3002\u8be5\u63a5\u53e3\u91cc\u67095\u4e2a\u65b9\u6cd5\uff0c\u63a5\u6536\u5230\u8bf7\u6c42\u65f6\u5224\u65ad\u662f\u5426\u80fd\u8bfb(canRead)\uff0c\u80fd\u8bfb\u5219\u8bfb(read)\uff1b\u8fd4\u56de\u7ed3\u679c\u65f6\u5224\u65ad\u662f\u5426\u80fd\u5199(canWrite)\uff0c\u80fd\u5199\u5219\u5199(write)\uff0c\u4ee5\u53ca\u83b7\u53d6\u652f\u6301\u7684 MediaType(application\/json\u4e4b\u7c7b)\u65b9\u6cd5\u3002<\/p>\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=\"\">boolean canRead(Class&lt;?> clazz, MediaType mediaType);\n\nboolean canWrite(Class&lt;?> clazz, MediaType mediaType);\n\nList&lt;MediaType> getSupportedMediaTypes();\n\nT read(Class&lt;? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException;\n\nvoid write(T t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException;<\/pre>\n\n\n\n<p><strong>3. HttpMessageConverter\u8f6c\u6362\u539f\u7406<\/strong><\/p>\n\n\n\n<p>\u5229\u7528SpringMVC\u6846\u67b6\uff0c\u53ef\u4ee5\u4f7f\u5f97\u6211\u4eec\u5728\u5f00\u53d1\u65f6\uff0c\u53ea\u8981\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528@RequestBody\u548c@ResponseBody\u4e24\u4e2a\u6ce8\u89e3\uff0c\u5c31\u53ef\u4ee5\u5206\u522b\u5b8c\u6210\u4ece\u8bf7\u6c42\u62a5\u6587\u5230\u5bf9\u8c61\u548c\u4ece\u5bf9\u8c61\u5230\u54cd\u5e94\u62a5\u6587\u7684\u8f6c\u6362\u3002\u800c\u5728\u6e90\u7801\u5185\u90e8\uff0c\u5176\u5b9e\u8fd9\u79cd\u7075\u6d3b\u7684\u6d88\u606f\u8f6c\u6362\u673a\u5236\u5c31\u662f\u5229\u7528HttpMessageConverter\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n\n\n\n<p>\u5b9e\u73b0\u8fc7\u7a0b\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-1024x309.png\" alt=\"\" class=\"wp-image-12848\" width=\"503\" height=\"151\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-1024x309.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-300x91.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-768x232.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-830x251.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-230x69.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-350x106.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84-480x145.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-84.png 1304w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><\/figure><\/div>\n\n\n\n<p>SpringMVC\u5728\u542f\u52a8\u65f6\u4f1a\u81ea\u52a8\u914d\u7f6e\u4e00\u4e9b\u9ed8\u8ba4\u7684HttpMessageConverter\u8f6c\u6362\u5668\uff0c\u5728 WebMvcConfigurationSupport\u7c7b\u4e2d\u6dfb\u52a0\u4e86\u7f3a\u7701\u7684MessageConverter\uff0c\u6bd4\u5982MappingJackson2HttpMessageConverter\uff0cStringHttpMessageConverter\u7b49\u3002<\/p>\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=\"\">protected final void addDefaultHttpMessageConverters(List&lt;HttpMessageConverter&lt;?>> messageConverters) {\n        StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();\n        stringConverter.setWriteAcceptCharset(false);\n\n        messageConverters.add(new ByteArrayHttpMessageConverter());\n        messageConverters.add(stringConverter);\n        messageConverters.add(new ResourceHttpMessageConverter());\n        messageConverters.add(new SourceHttpMessageConverter&lt;Source>());\n        messageConverters.add(new AllEncompassingFormHttpMessageConverter());\n\n        if (romePresent) {\n            messageConverters.add(new AtomFeedHttpMessageConverter());\n            messageConverters.add(new RssChannelHttpMessageConverter());\n        }\n\n        if (jackson2XmlPresent) {\n            ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build();\n            messageConverters.add(new MappingJackson2XmlHttpMessageConverter(objectMapper));\n        }\n        else if (jaxb2Present) {\n            messageConverters.add(new Jaxb2RootElementHttpMessageConverter());\n        }\n\n        if (jackson2Present) {\n            ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();\n            messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));\n        }\n        else if (gsonPresent) {\n            messageConverters.add(new GsonHttpMessageConverter());\n        }\n    }<\/pre>\n\n\n\n<p>\u4ece\u6e90\u7801\u4e2d\u53ef\u4ee5\u770b\u5230\uff0cSpringMVC\u4e2d\u4f7f\u7528Jackson\u5e93\u6216Gson\u5e93\u6765\u8f6c\u6362json\u5b57\u7b26\u4e32\uff0c\u4f7f\u7528\u4f7f\u7528Jackson XML\u6216\u8005JAXB2\u6765\u8f6c\u6362XML\u3002<\/p>\n\n\n\n<p>\u800c\u5982\u679c\u6211\u4eec\u6ca1\u6709\u914d\u7f6e\u81ea\u5df1\u7684 MessageConverter\uff0cSpringMVC\u542f\u52a8\u65f6\u5c31\u4f1a\u8c03\u7528 addDefaultHttpMessageConverters()\u65b9\u6cd5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"383\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-1024x383.png\" alt=\"\" class=\"wp-image-12849\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-1024x383.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-300x112.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-768x287.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-830x310.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-230x86.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-350x131.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85-480x179.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-85.png 1322w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>4. SpringBoot\u4e2d\u81ea\u5b9a\u4e49HttpMessageConverters\u7684\u5b9e\u73b0\u601d\u8def<\/strong><\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u60f3\u5728SpringBoot\u4e2d\u81ea\u5b9a\u4e49\u81ea\u5df1\u7684HttpMessageConverters\u8be5\u600e\u4e48\u529e\u5462\uff1f\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528HttpMessageConverters\u6dfb\u52a0HttpMessageConverter\u539f\u751f\u8f6c\u6362\u7c7b\u6216\u81ea\u5b9a\u4e49\u8f6c\u6362\u7c7b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\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=\"\">import org.springframework.boot.autoconfigure.web.HttpMessageConverters;\nimport org.springframework.context.annotation.*;\nimport org.springframework.http.converter.*;\n\n@Configuration\npublic class MyConfiguration {\n\n    @Bean\n    public HttpMessageConverters customConverters() {\n        HttpMessageConverter&lt;?> additional = ...\n        HttpMessageConverter&lt;?> another = ...\n        return new HttpMessageConverters(additional, another);\n    }\n}<\/pre>\n\n\n\n<p>\u4ece\u4e0a\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u770b\u5230\uff0c\u53ef\u4ee5\u628aHttpMessageConverter\u7c7b\u6dfb\u52a0\u5230converters\u5217\u8868\u4e2d\uff0c\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u6765\u8986\u76d6\u9ed8\u8ba4\u7684\u8f6c\u6362\u5668\u5217\u8868(converters)\u3002<\/p>\n\n\n\n<p><strong>5. \u81ea\u5b9a\u4e49\u6d88\u606f\u8f6c\u6362\u5668\u7684\u65b9\u5f0f<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u81ea\u5b9a\u4e49\u81ea\u5df1\u7684\u6d88\u606f\u8f6c\u6362\u5668\u6765\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\uff0c\u4e00\u822c\u81ea\u5b9a\u4e49\u6d88\u606f\u8f6c\u6362\u5668\u6709\u4e24\u79cd\u65b9\u5f0f:<\/p>\n\n\n\n<p>1. \u4f7f\u7528Spring\u6216\u8005\u7b2c\u4e09\u65b9\u63d0\u4f9b\u7684\u73b0\u6210\u7684HttpMessageConverter\uff1b<\/p>\n\n\n\n<p>2. \u81ea\u5df1\u91cd\u5199\u4e00\u4e2aHttpMessageConverter\u3002<\/p>\n\n\n\n<p><strong>\u4e09.\u4f7f\u7528FastJsonHttpMessageConverter\u66ff\u6362\u9ed8\u8ba4\u7684\u8f6c\u6362\u5668<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u63a5\u4e0b\u6765\u9a6c\u54e5\u5c31\u901a\u8fc7\u4e00\u4e2a\u6848\u4f8b\uff0c\u5229\u7528FastJsonHttpMessageConverter\u6765\u66ff\u6362\u6389\u9ed8\u8ba4\u7684\u6d88\u606f\u8f6c\u6362\u5668\u3002<\/p>\n\n\n\n<p><strong>1. \u521b\u5efaSpringBoot\u9879\u76ee<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u5728\u4e4b\u524d\u7684\u57fa\u7840\u4e0a\uff0c\u65b0\u5efa\u4e00\u4e2a\u6a21\u5757demo10\uff0c\u5e76\u5c06\u5176\u6539\u9020\u4e3aSpringBoot\u9879\u76ee\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-1024x1005.png\" alt=\"\" class=\"wp-image-12850\" width=\"284\" height=\"278\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-1024x1005.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-300x294.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-768x754.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-830x815.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-230x226.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-350x343.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86-480x471.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-86.png 1290w\" sizes=\"(max-width: 284px) 100vw, 284px\" \/><\/figure><\/div>\n\n\n\n<p><strong>2. \u6dfb\u52a0FastJson\u4f9d\u8d56<\/strong><\/p>\n\n\n\n<p>\u5728SpringBoot\u9879\u76ee\u4e2d\uff0c\u5f53\u6211\u4eec\u5728\u63a7\u5236\u5668\u7c7b\u6216\u8005\u5176\u5185\u90e8\u7684\u65b9\u6cd5\u4e0a\u6dfb\u52a0@RestController\u6ce8\u89e3\u548c@ResponseBody\u6ce8\u89e3\u540e\uff0c\u9ed8\u8ba4\u4f1a\u4f7f\u7528jackson\u63d2\u4ef6\u6765\u8fd4\u56dejson\u683c\u5f0f\u7684\u6570\u636e\uff0c\u4f46\u662f\u6211\u4eec\u4e5f\u53ef\u4ee5\u5229\u7528fastjson\u4e3a\u6211\u4eec\u63d0\u4f9b\u7684FastJsonHttpMessageConverter\u6765\u8fd4\u56dejson\u683c\u5f0f\u7684\u6570\u636e\u3002\u6240\u4ee5\u8fd9\u91cc\u9996\u5148\u5f15\u5165fastjson\u7684\u4f9d\u8d56\u5305\u3002<\/p>\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=\"\">&lt;dependency>\n   &lt;groupId>com.alibaba&lt;\/groupId>\n   &lt;artifactId>fastjson&lt;\/artifactId>\n   &lt;version>1.2.61&lt;\/version>\n&lt;\/dependency><\/pre>\n\n\n\n<p><strong>3. \u914d\u7f6eFastJsonHttpMessageConverter<\/strong><\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5b9e\u73b0WebMvcConfigurer\u63a5\u53e3\uff0c\u6765\u914d\u7f6eFastJsonHttpMessageConverter\uff0c\u5728Spring Boot2.0\u7248\u672c\u4ee5\u540e\u63a8\u8350\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u6765\u8fdb\u884cWeb\u914d\u7f6e\uff0c\u8fd9\u6837\u4e0d\u4f1a\u8986\u76d6\u6389Spring Boot\u7684\u4e00\u4e9b\u9ed8\u8ba4\u914d\u7f6e\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5728\u9879\u76ee\u5305\u4e2d\u521b\u5efaconfig\u5305\uff0c\u5e76\u521b\u5efa\u4e00\u4e2aCustomWebMvcConfigurer\u7c7b\uff0c\u4ee3\u7801\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-1024x650.png\" alt=\"\" class=\"wp-image-12851\" width=\"425\" height=\"270\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-1024x650.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-300x190.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-768x488.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-830x527.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-230x146.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-350x222.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87-480x305.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-87.png 1304w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/figure><\/div>\n\n\n\n<p>CustomWebMvcConfigurer\u7c7b\u4e2d\u7684\u5185\u5bb9\uff1a<\/p>\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=\"\">\/**\n *\u5b9e\u73b0WebMvcConfigurer\u63a5\u53e3\u6765\u914d\u7f6eFastJsonHttpMessageConverter,\n *Spring Boot2.0\u7248\u672c\u4ee5\u540e\u63a8\u8350\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u6765\u8fdb\u884cweb\u914d\u7f6e\uff0c\u8fd9\u6837\u4e0d\u4f1a\u8986\u76d6\u6389Spring Boot\u7684\u4e00\u4e9b\u9ed8\u8ba4\u914d\u7f6e.\n *\/\n@Configuration\npublic class CustomWebMvcConfigurer implements WebMvcConfigurer {\n\n    @Override\n    public void extendMessageConverters(List&lt;HttpMessageConverter&lt;?>> converters) {\n        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();\n        FastJsonConfig config = new FastJsonConfig();\n        config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);\n        converter.setFastJsonConfig(config);\n        converter.setDefaultCharset(Charset.forName(\"UTF-8\"));\n        converters.add(converter);\n    }\n\n}<\/pre>\n\n\n\n<p><strong>3.1 FastJson\u4e2d\u7684SerializerFeature\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<p>\u5728FastJson\u914d\u7f6e\u5b9e\u4f53\u65f6\uff0c\u4f1a\u8c03\u7528setSerializerFeatures\u65b9\u6cd5\u914d\u7f6e\u591a\u4e2a\u8fc7\u6ee4\u65b9\u5f0f\uff0c\u5e38\u7528\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-882x1024.png\" alt=\"\" class=\"wp-image-12852\" width=\"378\" height=\"439\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-882x1024.png 882w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-258x300.png 258w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-768x892.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-830x964.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-230x267.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-350x406.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88-480x557.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-88.png 1264w\" sizes=\"(max-width: 378px) 100vw, 378px\" \/><\/figure><\/div>\n\n\n\n<p>3.2 \u5e38\u7528\u7684SerializerFeature\u91ca\u4e49<\/p>\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=\"\">QuoteFieldNames,\/\/\u8f93\u51fakey\u65f6\u662f\u5426\u4f7f\u7528\u53cc\u5f15\u53f7,\u9ed8\u8ba4\u4e3atrue;\n\nUseSingleQuotes,\/\/\u4f7f\u7528\u5355\u5f15\u53f7\u800c\u4e0d\u662f\u53cc\u5f15\u53f7,\u9ed8\u8ba4\u4e3afalse;\n\nWriteMapNullValue,\/\/\u662f\u5426\u8f93\u51fa\u503c\u4e3anull\u7684\u5b57\u6bb5,\u9ed8\u8ba4\u4e3afalse; \n\nWriteEnumUsingToString,\/\/Enum\u8f93\u51faname()\u6216\u8005original,\u9ed8\u8ba4\u4e3afalse;\n\nUseISO8601DateFormat,\/\/Date\u4f7f\u7528ISO8601\u683c\u5f0f\u8f93\u51fa\uff0c\u9ed8\u8ba4\u4e3afalse;\n\nWriteNullListAsEmpty,\/\/List\u5b57\u6bb5\u5982\u679c\u4e3anull,\u8f93\u51fa\u4e3a[],\u800c\u975enull;\n\nWriteNullStringAsEmpty,\/\/\u5b57\u7b26\u7c7b\u578b\u5b57\u6bb5\u5982\u679c\u4e3anull,\u8f93\u51fa\u4e3a\"\",\u800c\u975enull; \n \nWriteNullNumberAsZero,\/\/\u6570\u503c\u5b57\u6bb5\u5982\u679c\u4e3anull,\u8f93\u51fa\u4e3a0,\u800c\u975enull;\n\nWriteNullBooleanAsFalse,\/\/Boolean\u5b57\u6bb5\u5982\u679c\u4e3anull,\u8f93\u51fa\u4e3afalse,\u800c\u975enull;\n\nSkipTransientField,\/\/\u5982\u679c\u662ftrue\uff0c\u7c7b\u4e2d\u7684Get\u65b9\u6cd5\u5bf9\u5e94\u7684Field\u662ftransient\uff0c\u5e8f\u5217\u5316\u65f6\u5c06\u4f1a\u88ab\u5ffd\u7565\u3002\u9ed8\u8ba4\u4e3atrue;\n\nSortField,\/\/\u6309\u5b57\u6bb5\u540d\u79f0\u6392\u5e8f\u540e\u8f93\u51fa,\u9ed8\u8ba4\u4e3afalse;\n\n@Deprecated\nWriteTabAsSpecial,\/\/\u628a\\t\u505a\u8f6c\u4e49\u8f93\u51fa,\u9ed8\u8ba4\u4e3afalse;\n\nPrettyFormat,\/\/\u7ed3\u679c\u662f\u5426\u683c\u5f0f\u5316,\u9ed8\u8ba4\u4e3afalse;\n\nWriteClassName,\/\/\u5e8f\u5217\u5316\u65f6\u5199\u5165\u7c7b\u578b\u4fe1\u606f,\u9ed8\u8ba4\u4e3afalse,\u53cd\u5e8f\u5217\u5316\u662f\u9700\u7528\u5230;\n\nDisableCircularReferenceDetect,\/\/\u6d88\u9664\u5bf9\u540c\u4e00\u5bf9\u8c61\u5faa\u73af\u5f15\u7528\u7684\u95ee\u9898,\u9ed8\u8ba4\u4e3afalse;\n\nWriteSlashAsSpecial,\/\/\u5bf9\u659c\u6760'\/'\u8fdb\u884c\u8f6c\u4e49;\n\nBrowserCompatible,\/\/\u5c06\u4e2d\u6587\u90fd\u4f1a\u5e8f\u5217\u5316\u4e3a\\uXXXX\u683c\u5f0f\uff0c\u5b57\u8282\u6570\u4f1a\u591a\u4e00\u4e9b\uff0c\u4f46\u662f\u80fd\u517c\u5bb9IE 6\uff0c\u9ed8\u8ba4\u4e3afalse;\n\nWriteDateUseDateFormat,\/\/\u5168\u5c40\u4fee\u6539\u65e5\u671f\u683c\u5f0f,\u9ed8\u8ba4\u4e3afalse\u3002JSON.DEFFAULT_DATE_FORMAT = \"yyyy-MM-dd\";JSON.toJSONString(obj,SerializerFeature.WriteDateUseDateFormat);\n\nDisableCheckSpecialChar,\/\/\u4e00\u4e2a\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u5c5e\u6027\u4e2d\u5982\u679c\u6709\u7279\u6b8a\u5b57\u7b26\u5982\u53cc\u5f15\u53f7\uff0c\u5c06\u4f1a\u5728\u8f6c\u6210json\u65f6\u5e26\u6709\u53cd\u659c\u6760\u8f6c\u79fb\u7b26\u3002\u5982\u679c\u4e0d\u9700\u8981\u8f6c\u4e49\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u5c5e\u6027,\u9ed8\u8ba4\u4e3afalse.\n\n<\/pre>\n\n\n\n<p><strong>4. \u521b\u5efa\u5bf9\u8c61\u5b9e\u4f53<\/strong><\/p>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u518d\u521b\u5efa\u4e00\u4e2a\u201ccom.yyg.boot.domain\u201d\u5305\uff0c\u5728\u8fd9\u91cc\u521b\u5efa\u4e00\u4e2aUser\u5b9e\u4f53\u7c7b\u3002<\/p>\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.yyg.boot.domain;\n\nimport lombok.AllArgsConstructor;\nimport lombok.Data;\n\n@Data\n@AllArgsConstructor\npublic class User {\n\n    private String name;\n\n    private String address;\n\n}<\/pre>\n\n\n\n<p><strong>5. \u521b\u5efaController<\/strong><\/p>\n\n\n\n<p>\u518d\u521b\u5efa\u4e00\u4e2a\u201ccom.yyg.boot.web\u201d\u5305\uff0c\u5728\u91cc\u9762\u521b\u5efaController\u7c7b\uff0c\u5b9a\u4e49\u4e00\u4e2a\u201d\/users\u201c\u63a5\u53e3\u3002<\/p>\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.yyg.boot.web;\n\nimport com.yyg.boot.domain.User;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RequestMethod;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\n@RestController\npublic class UserController {\n\n    @RequestMapping(value = \"\/users\", method = RequestMethod.GET)\n    public Object getList() {\n        List&lt;User> list = new ArrayList&lt;>();\n        \/\/\u6d4b\u8bd5\u5b57\u7b26\u4e32\u6709null\u7684\u60c5\u51b5\n        User u1 = new User(\"\u4e00\u4e00\u54e5\", null);\n        list.add(u1);\n        return list;\n    }\n\n}<\/pre>\n\n\n\n<p><strong>6. \u521b\u5efa\u7a0b\u5e8f\u5165\u53e3\u7c7b<\/strong><\/p>\n\n\n\n<p>\u6700\u540e\u6211\u4eec\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u542f\u52a8\u7c7b\u3002<\/p>\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.yyg.boot;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n\/**\n * \u81ea\u5b9a\u4e49HttpMessageConverter\n *\/\n@SpringBootApplication\npublic class ConvertApplication {\n\n    public static void main(String[] args) {\n        SpringApplication.run(ConvertApplication.class, args);\n    }\n\n}<\/pre>\n\n\n\n<p><strong>7. \u9879\u76ee\u7ed3\u6784<\/strong><\/p>\n\n\n\n<p>\u6700\u540e\u6574\u4e2a\u9879\u76ee\u7684\u4ee3\u7801\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u5404\u4f4d\u53ef\u4ee5\u53c2\u8003\u521b\u5efa\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-89-888x1024.png\" alt=\"\" class=\"wp-image-12853\" width=\"336\" height=\"386\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-89-888x1024.png 888w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-89-260x300.png 260w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-89-230x265.png 230w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/figure><\/div>\n\n\n\n<p><strong>8. \u542f\u52a8\u9879\u76ee\u8fdb\u884c\u6d4b\u8bd5<\/strong><\/p>\n\n\n\n<p>\u6700\u540e\u6211\u4eec\u542f\u52a8\u9879\u76ee\uff0c\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95eehttp:\/\/localhost:8080\/users\u63a5\u53e3\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a\u6211\u4eecCustomWebMvcConfigurer\u7c7b\u7684\u4ee3\u7801\u4e2d\uff0c\u6ca1\u6709\u914d\u7f6eWriteMapNullValue\uff0c\u6240\u4ee5\u5982\u679c\u8fd4\u56de\u7ed3\u679c\u4e2d\u6709null\u503c\u5219\u4e0d\u663e\u793a\uff0c\u6548\u679c\u5982\u4e0b:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-1024x765.png\" alt=\"\" class=\"wp-image-12854\" width=\"425\" height=\"317\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-1024x765.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-300x224.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-768x574.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-830x620.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-230x172.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-350x262.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90-480x359.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-90.png 1084w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/figure><\/div>\n\n\n\n<p>\u63a5\u7740\u6211\u4eec\u5728CustomWebMvcConfigurer\u4e2d\u6dfb\u52a0WriteMapNullValue\u914d\u7f6e\uff0c\u5982\u4e0b\u56fe:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"132\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-1024x132.png\" alt=\"\" class=\"wp-image-12855\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-1024x132.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-300x39.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-768x99.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-1536x199.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-830x107.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-230x30.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-350x45.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91-480x62.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-91.png 2042w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u7136\u540e\u91cd\u65b0\u542f\u52a8\u9879\u76ee\u5e76\u8bbf\u95ee\uff0c\u4ece\u7ed3\u679c\u53ef\u4ee5\u770b\u51fa\uff0c\u6211\u4eec\u914d\u7f6e\u7684\u6d88\u606f\u8f6c\u6362\u5668\u8d77\u4e86\u4f5c\u7528\uff0cnull\u503c\u5c55\u793a\u4e86\u51fa\u6765\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-1024x620.png\" alt=\"\" class=\"wp-image-12856\" width=\"411\" height=\"248\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-1024x620.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-300x182.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-768x465.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-830x502.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-230x139.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-350x212.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92-480x291.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-92.png 1120w\" sizes=\"(max-width: 411px) 100vw, 411px\" \/><\/figure><\/div>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u5728CustomWebMvcConfigurer\u7c7b\u4e2d\uff0c\u518d\u6539\u4e3aWriteNullStringAsEmpty\u914d\u7f6e\uff0c\u5982\u4e0b\u56fe:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"159\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-1024x159.png\" alt=\"\" class=\"wp-image-12857\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-1024x159.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-300x47.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-768x120.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-1536x239.png 1536w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-830x129.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-230x36.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-350x55.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93-480x75.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-93.png 1554w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u7136\u540e\u91cd\u65b0\u542f\u52a8\u9879\u76ee\u5e76\u8bbf\u95ee\uff0c\u4ece\u7ed3\u679c\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u6211\u4eec\u914d\u7f6e\u7684\u6d88\u606f\u8f6c\u6362\u5668\u53c8\u8d77\u4e86\u4f5c\u7528\uff0cnull\u88ab\u66ff\u6362\u6210\u4e86&#8221;&#8221;\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-1024x610.png\" alt=\"\" class=\"wp-image-12858\" width=\"386\" height=\"229\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-1024x610.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-300x179.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-768x458.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-830x494.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-230x137.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-350x208.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94-480x286.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/09\/image-94.png 1118w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u7ed3\u8bed<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2aConfig\u914d\u7f6e\u7c7b\uff0c\u6211\u4eec\u5c31\u628a\u81ea\u5b9a\u4e49\u7684HttpMessageConverter\u7c7b\u6574\u5408\u5230\u4e86SpringBoot\u4e2d\uff0c\u66ff\u6362\u6389\u4e86\u9ed8\u8ba4\u7684HttpMessageConverter\u7c7b\uff0c\u4f60\u4f1a\u53d1\u73b0\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u5176\u5b9e\u4e5f\u975e\u5e38\u7684\u7b80\u5355\uff0c\u6211\u4eec\u57fa\u672c\u6ca1\u6709\u8fdb\u884c\u8fc7\u591a\u7684\u53c2\u4e0e\u3002\u4eca\u5929\u7684\u5185\u5bb9\u4f60\u5b66\u4f1a\u4e86\u5417\uff1f\u8bc4\u8bba\u533a\u548c\u5927\u5bb6\u8ba8\u8bba\u4e00\u4e0b\u5427\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 SpringBoot\u4e25\u683c\u7684\u6765\u8bf4\uff0c\u5e94\u8be5\u662f\u4e00\u79cd\u8d1f\u8d23\u628a\u5176\u4ed6\u5df2\u6709\u6846\u67b6\u6574\u5408\u5728\u4e00\u8d77\u7684\u5de5\u5177\uff0cSpringBoot\u4e3b\u8981\u662f [&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\/12847"}],"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=12847"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/12847\/revisions"}],"predecessor-version":[{"id":12859,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/12847\/revisions\/12859"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}