Springboot-10请求处理(Servlet、复杂参数、自定义)

1、Servlet API:

WebRequest、ServletRequest、MultipartRequest、 HttpSession、javax.servlet.http.PushBuilder、Principal、InputStream、Reader、HttpMethod、Locale、TimeZone、ZoneId

2、复杂参数

1、Map、Model(map、model里面的数据会被放在request的请求域 ),即等价于给HttpServletRequest 放数据(request.setAttribute)。
2、Map、Model类型的参数,会返回 mavContainer.getModel();—> BindingAwareModelMap 是Model 也是Map。

/**
*请求tset,然后forward转发给success
**/
@GetMapping("/test")
    public String testParams(Map<Object,String> map,
                             Model model,
                             HttpServletRequest httpServletRequest,
                             HttpServletResponse httpServletResponse){
        map.put("yan1","1");
        model.addAttribute("yan2","2");
        httpServletRequest.setAttribute("yan3","3");
        httpServletResponse.addCookie(new Cookie("yan4","pige"));
        return "forward:/success";
    }

    @GetMapping("/success")
    public  Map test(@RequestAttribute(value = "msg",required = false) String msg,
                        HttpServletRequest httpRequest){
        Map<String,Object> objectStringMap = new HashMap<>();
        Object map = httpRequest.getAttribute("yan1");
        Object model = httpRequest.getAttribute("yan2");
        Object request = httpRequest.getAttribute("yan3");
        Object response = httpRequest.getAttribute("yan4");
        objectStringMap.put("yan1",map);
        objectStringMap.put("yan2",model);
        objectStringMap.put("yan3",request);
        objectStringMap.put("yan4",response);

        return objectStringMap;
    }
3、自定义参数

前端请求提交的参数,后端默认接受为一个对象;

访问:http://localhost:8003/user/user?name=%22zhangsan%22

@GetMapping("/user")
    public User user(User user){
        return user;
    }

结果:

{"id":null,"name":"\"zhangsan\"","password":null,"sex":null,"age":null,"createTime":null,"updateTime":null,"deleted":null,"version":null,"departId":null}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值