首页 > 其他分享 >spring boot——请求与参数校验——request原理&获去请求行请求示例

spring boot——请求与参数校验——request原理&获去请求行请求示例

时间:2023-01-08 14:33:06浏览次数:40  
标签:请求 示例 spring request System println import out

request原理:

 

 

 

 

 

 

 

 

 

 

 

 

 

request功能:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

代码示例:

package org.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

@RestController
public class ParamController
{
    @RequestMapping(value = "/test1")
    public void test1(HttpServletRequest request)
    {
        System.out.println(request.getMethod());   //获取请求方式;

        System.out.println(request.getContextPath());  //获取虚拟目录

        System.out.println(request.getServletPath());  //获取servlet路径

        System.out.println(request.getQueryString());   //获取请求参数

        System.out.println(request.getRequestURI());   //获取请求URI,部分

        System.out.println(request.getRequestURL());   //获取请求URI,全部



    }
}

 

 

 

 

 

 

 

响应:

 

 

 

标签:请求,示例,spring,request,System,println,import,out
From: https://www.cnblogs.com/xiaobaibailongma/p/17034648.html

相关文章