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>
     
     
     
  • 相关阅读:
    使用Xshell为xftp开ssh通道代理
    linux下查找svn的相关目录的命令
    linux服务器A远程连接服务器B的mysql及1045错误
    怎样下载带权限认证的文件?
    Vue项目打包部署总结
    Vue项目打包压缩:让页面更快响应
    axios请求失败自动重发
    可用的后台管理系统
    vue组件间方式总结
    非脚手架创建vue项目,并使用webpack打包
  • 原文地址:https://www.cnblogs.com/newcityboy/p/11935009.html
Copyright © 2011-2022 走看看