zoukankan      html  css  js  c++  java
  • SpringMVC后台接受前台传值的方法

    1.HttpRequestServlet 接收前台传值

    @RequestMapping("/go5")
        public String hello5(HttpServletRequest request){
            String name=request.getParameter("uname");
            String id=request.getParameter("uid");
            System.out.println(id+"----"+name);
            return "/WEB-INF/jsp/index.jsp";
        }

    2.直接接收前台传值

     //接收单个参数
         @RequestMapping("/hello")
         public String hello(String name){
             System.out.println(name);
             return "/WEB-INF/jsp/index.jsp";
         }
    //接收多个参数
         @RequestMapping("/go2")
        public String hello3(String name,int id){
             System.out.println(name);
             System.out.println(id);
             return "/WEB-INF/jsp/index.jsp";
         }

    3.以对象形式接收前台传递的数据

    //以对象形式接受参数
         @RequestMapping("/go4")
         public String hello5( Student stu){
             System.out.println(stu.getName());
             System.out.println(stu.getId());
             return "/WEB-INF/jsp/index.jsp";
         }
    public class Student {//类中必须要有无参数构造函数不然会有java.lang.NoSuchMethodException: org.entity.Student.<init>()错误
         private int id;
         private String name;
        public Student(int id, String name) {
            super();
            this.id = id;
            this.name = name;
        }
        
        public Student() {
            super();
        }
    }

    4.restful风格

    //restful风格
         @RequestMapping("/detete/{uid}/{uname}")
         public String hello2(@PathVariable("uid")int id,@PathVariable("uname")String name){
             System.out.println(id+"  ---->"+name);
             return "/WEB-INF/jsp/index.jsp";
         }
  • 相关阅读:
    [蓝桥杯][算法提高VIP]传染病控制
    PAT甲级第二次真题练习
    BFS()搜索加上hash
    PAT甲级第一次真题练习
    一个小练习题
    八皇后
    【Noi 1994 删数问题】【openjudge 3528 最小新整数(变式)】整型与字符
    【openjudge 2469 电池的寿命】算法与思维
    MarkDown测试
    HNOI 2017 怼大佬
  • 原文地址:https://www.cnblogs.com/qie-zi/p/8764421.html
Copyright © 2011-2022 走看看