[Spring MVC] learning notes -- @ Controller, mvc -- @ controller

Source: Internet
Author: User

[Spring MVC] learning notes -- @ Controller, mvc -- @ controller

Before explaining @ Controller, describe the official Spring MVC document.

Some people may be like me. When I first got started with Spring MVC, I found that the Spring MVC project could not be found on the Spring website.

This is because Spring MVC is put in Spring Framework.

You can open The reference of Spring Framework. Some of them specifically introduce Spring MVC, "V. The Web ".

 

Controller is C in MVC.

 

@ Controller is used in Spring-MVC to mark a class as controller to provide services.

@Controllerpublic class HelloWorldController {    @RequestMapping("/helloWorld")    public String helloWorld(Model model) {        return "helloWorld";    }       }

To automatically find our defined controller, you need to add a line to the xml file.

<context:component-scan base-package="xxx.xxx"/>

 


What is @ Controller @ RequestMapping in springmvc?

Annotation function ah, @ Controller is to register the Controller you write, @ RequestMapping is to register the path you access
 
In spring mvc, can methods in the Controller be called in another Controller layer?

If it is a method, I don't know if it can be called. I haven't tried it.
If it is a controller, you can certainly not directly call it, you can only jump.

If you need to remove the method, pull it out and do not put it in the Controller, because it does not conform to the MVC design philosophy.

If yes, It is not thread-safe.

Related Article

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.