With this small note - common annotations of springmvc

springmvc knowledge
spring-mvc
web.xml configuration DispatcherServlet
{servlet-name}-servlet.xml (own configuration file)
scan package <context:component-scan base-package="cn.mvc.controller"/>
annotation driver (configuration handlerMapping, HandlerAdatper)
<mvc:annotation-driven/>
view resolver (org.springframework.web.servlet.view.InternalResourceViewResolver)
prefix (prefix)
suffix (suffix)
return view form === prefix + entity name + suffix
File upload is required -- configure the file upload code.
If there is a custom interceptor, you need to configure the use of the <mvc:interceptors>
annotation. The
class annotation
@Controller indicates that the current class is a Controller
@RequestMapping(value="access path")
method The annotation
@RequestMapping(value="path", method="limit request method", params="limit request parameters" )
@ResponseBody --- Indicates that the returned object is automatically converted into json and returned to the foreground (processing ajax requests)
@ResponseStatus sets the corresponding state code (understanding)
method parameter annotation
@RequestBody --- accepts json format data can be a collection, can be a single object, convert to java background to receive
@PathVariable() ---- accept the path in the The placeholder /test/{itemid} can accept itemid 
@RequestParam (value=“the key to pass the parameter’”, required=whether the parameter must be passed, defaultValue: if the default value of the parameter is not passed) Accept the request parameter
@CookieValue(value ="cookieName") can directly obtain data from the specified cookie.
Some objects accept
the built-in object of serlvet (you can get it by directly defining parameters in the method)
request
resposne
session
pojo
object . You can use the collection
to redefine the object directly.
An object, turn the collection into an attribute in the object, and write the object on the parameters of the method.
Interceptor
1. Implement HandlerInterceptor
2. Complete the specified three methods
preHandle (pre-method, return type, boolean, true to continue backwards Execute, false, end execution
Post method: postHandle (after executing Handler)
Completion method afterCompletion() If the preHandler of this class returns true, the
web.xml configuration DispatcherServlet
{servlet-name}-servlet.xml (own configuration file) will be executed to
scan the package <context:component-scan base-package= "cn.mvc.controller"/>
Annotation-driven (handlerMapping, HandlerAdatper configured)
<mvc:annotation-driven/>
view resolver (org.springframework.web.servlet.view.InternalResourceViewResolver)
prefix (prefix)
suffix (suffix)
The form of the returned view === prefix + entity name + suffix File upload is
required -- then configure the file upload code
If there is a custom interceptor, you need to configure the use of the <mvc:interceptors>
annotation The
class annotation
@Controller indicates that the current class is A Controller
@RequestMapping(value="access path")
method annotation
@RequestMapping(value="path", method="limited request method", params="limited request parameters" )
@ResponseBody --- Indicates that the returned object is automatically converted to json
@ResponseStatus sets the corresponding state code (understanding)
method parameter annotation
@RequestBody --- accepts json format data, which can be a collection or a single object
@PathVariable() --- accepts the placeholder /test/ in the path {itemid} can accept itemid 
@RequestParam (value=“pass parameter key’”, required=whether this parameter must be passed, defaultValue: if the default value of the parameter is not passed) Accept request parameter
@CookieValue(value="cookieName") OK Get data directly from the specified cookie
Some objects accept
the built-in object of serlvet (you can get it by defining parameters directly in the method)
request
resposne
session
pojo
object You can use the collection
to redefine an object by directly defining the object, and change the collection into a
As an attribute in the object, on the parameters of the method, write this object
Interceptor
1. Implement HandlerInterceptor
2. Complete the three methods
preHandle specified (pre-method, return type, boolean, true continue to execute backwards, false, end execution
Post method: postHandle (after executing Handler)
The completion method afterCompletion() will be executed if the preHandler of the class returns true

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324726611&siteId=291194637