package com.hope.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* @author newcityman
* @date 2019/11/25 - 22:55
*/
@Controller("helloController")
@RequestMapping(path = "/user")
public class HelloController {
@RequestMapping(path = "/hello")
public String sayHello(){
System.out.println("hello springmvc");
return "success";
}
/**
* RequestMapping注解
* @return
*/
@RequestMapping(path = "/testRequestMapping",method = {RequestMethod.GET}, //path和value有等同效果
params = {"username=hehe"},headers = {"Accept"})
public String testRequestMapping(){
System.out.println("测试RequestMapping");
return "success";
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>入门</title>
</head>
<body>
<h3>入门程序</h3>
<%--<a href="hello">入门程序</a>--%>
<a href="user/testRequestMapping?username=hehe">RequestMapping</a>
</body>
</html>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h3>入门成功</h3>
</body>
</html>