@RequestMapping role

Article Directory

@RequestMapping role

  • @RequestMapping Is used to process a request for comments address mapping, it can be used for class or method.
    • For the class , the response to the request by any methods that are class address as the parent paths ;
    • A method , the upper represents an additional path in the parent class annotated method will access the address to the method.

Controller level code:

package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * 用于类上,可以没有
 */
@Controller
@RequestMapping("/demo")
public class DemoController {

    /**
     * 用于方法上,必须有
     */
    @GetMapping("/login")
    public String login() {
        return "login";
    }

}
  • Local browser input: http://localhost:8080/demo/loginwill jump to login.htmlpage
Published 70 original articles · won praise 38 · views 40000 +

Guess you like

Origin blog.csdn.net/qq_34745941/article/details/104760800