Kopite Kopite的博客

常见面试题

2017-05-10
Kopite

整理后端常见的面试题,加深对特定知识点的理解。

网络协议

java基础

spring mvc

  • 阐述servlet生命周期?servlet什么时候调用destroy()方法?
    答:参见:理解servlet

  • @ResponseBody注解的作用?返回的json格式在何处指定?
    答:@ResponseBody注解类位于spring-web-4.2.0.RELEASE-sources.jar,其描述如下:

Annotation that indicates a method return value should be bound to the web response body. Supported for annotated handler methods in Servlet environments. 

As of version 4.0 this annotation can also be added on the type level in which case it is inherited and does not need to be added on the method level.

该注解用于将Controller中方法返回的数据,通过适当的HttpMessageConverter转换为指定格式后,写入到该http请求的response body中。常用的一种HttpMessageConverterMappingJackson2HttpMessageConverter,其描述如下:

Implementation of HttpMessageConverter that can read and write JSON using Jackson 2.x's ObjectMapper. 
This converter can be used to bind to typed beans, or untyped HashMap instances. 
By default, this converter supports application/json and application/*+json. This can be overridden by setting the supportedMediaTypes property. 
The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder. 
Compatible with Jackson 2.1 and higher. 

spring framework

database

redis


Similar Posts

Comments