zoukankan      html  css  js  c++  java
  • springMVC中@requestMapper的使用和注意事项

    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>
     
     
     
  • 相关阅读:
    别让你的生活止于平庸!(摘)
    NSURLSession 请求
    第三方原理
    iOS实用的小技巧
    简书APP
    网络请求
    JQuery 简介
    struts2拦截器的实现原理及源码剖析
    hibernate配置文件注意点
    hibernate中三种状态
  • 原文地址:https://www.cnblogs.com/newcityboy/p/11935009.html
Copyright © 2011-2022 走看看