zoukankan      html  css  js  c++  java
  • SpringMVC 参数传递

    使用@RequestParam 注解获取GET请求或POST请求提交的参数;

    获取Cookie的值:使用@CookieValue :

    根据不同的Web请求方法,映射到不同的处理方法:
    使用登陆页面作示例,定义两个方法分辨对使用GET请求和使用POST请求访问login.htm时的响应。可以使用处理GET请求的方法显示视图,使用POST请求的方法处理业务逻辑;

    @Controller  
    public class LoginController {  
        @RequestMapping(value = "/login", method = RequestMethod.GET)  
        public String login() {  
            return "login";  
        }  
        @RequestMapping(value = "/login", method = RequestMethod.POST)  
        public String login2(HttpServletRequest request) {  
                String username = request.getParameter("username").trim();  
                System.out.println(username);  
            return "login2";  
        }  
    }  
    

    @PathVariable 取 URL 路径中的某个值为变量,如下

    @RequestMapping("/index/{username}")
    
    public String index(@PathVariable("username") String username)
    {
       System.out.print(username);
       return "index";
    }
    

      

    @RequestMapping中定义访问页面的URL模版,使用{}传入页面参数,使用@PathVariable 获取传入参数,即可通过地址:http://localhost:8080/crm/index/tanqimin.htm 访问;

  • 相关阅读:
    2019-04-02 cast and covert
    2019-04-01 为什么零售业务流行起来了?
    2019-04-01 银行的零售业务和对公业务
    服务器推送更新
    webpack 大概
    webpack
    react Hooks
    react 表单受控和非受控
    eslint规则
    react系列笔记:第三记-redux-saga
  • 原文地址:https://www.cnblogs.com/panie2015/p/5760517.html
Copyright © 2011-2022 走看看