The return value type of the SPRINGMVC processing method

Source: Internet
Author: User

1. Void: And does not use SERVLETAPI to jump, the request name will be jumped by default as the name of the attempt.

@RequestMapping ("/login")    publicvoid  Login (User User) {    }

Results:

void: Servletapi is used in the parameter, and jumps are made using Servletapi in the method. Then follow the Servletapi jump position to jump.

@RequestMapping ("/login")    publicvoid  Login ( HttpServletRequest Req,httpservletresponse resp) {        try  {            Req.getrequestdispatcher (  "success.jsp"). Forward (req, resp);         Catch (servletexception e) {            e.printstacktrace ();         Catch (IOException e) {            e.printstacktrace ();        }    }

Results:

With the SERVLETAPI jump page, it is possible to carry data through SERVLETAPI, but the model data through MVC cannot carry data.

2. Modelandview returns NULL, the page does not jump.

@RequestMapping ("/login")    public  Modelandview Login () {        System. out. println ("login==========");         return NULL ;    }

When the return value does not specify a view name, the default is to use the request name as the view name to jump.

@RequestMapping ("/login")    public  Modelandview Login () {         returnnew  Modelandview ();    }

When the return value specifies the view name, a jump is made according to the specified attempted name.

3. String: If the return value is NULL, then the request name jumps to the view name.

If the return value is specified, then the specified return value is used as the view name to jump, can carry the data through MODEL,MODELMAP, etc.

If the return value is prefixed with "ForWord" or "redired", the request is forwarded and redirected accordingly, and data cannot be carried through the MVC data model, which can be carried by SERVLETAPI.

4. Other types: can only be returned by JSON at asynchronous time.

The return value type of the SPRINGMVC processing method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.