简体   繁体   中英

How do i use spring mvc void controller method?

I am reading spring framework reference. When i read here . I found that spring mvc supports returning void types.And then i read some examples of using void .But these examples do not make me to understand when time to use void .Is there a better example of how to use it?

From the referenced document:

"... if the method handles the response itself (by writing the response content directly, declaring an argument of type ServletResponse / HttpServletResponse for that purpose) or if the view name is supposed to be implicitly determined through a RequestToViewNameTranslator (not declaring a response argument in the handler method signature)"

There are two conditions listed.

  1. If the method writes to the servletResponse directly. In this case, there is nothing for spring to do; a return value of void tells spring "I got this" and it does nothing with the response.
  2. If the view name can be determined vai a RequestToViewNameTranslator . In this situation, spring knows the view to return based on the request, so no return value is required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM