Springboot 3.需求携带参数的get请求
2021-06-22 23:05
标签:shm work pack turn method map stp add boot 还是拿来上节讲的代码: 访问的两种方式: Springboot 3.需求携带参数的get请求 标签:shm work pack turn method map stp add boot 原文地址:https://www.cnblogs.com/peiminer/p/9675947.htmlpackage com.course.server;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@RestController //被告诉我是你需要扫描的类
public class MyGetMethod {
@RequestMapping(value = "/getCookies",method = RequestMethod.GET) //访问的路径是什么
public String getCookies(HttpServletResponse response){
//HttpServerletRequest 装请求信息
//HttpServerletResponse 装响应信息
Cookie cookie = new Cookie("login","ture");
response.addCookie(cookie);
return "恭喜你获得cookies信息成功";
}
@RequestMapping(value = "/get/with/cookies",method = RequestMethod.GET)
public String getWithCookies(HttpServletRequest request){
Cookie[] cookies = request.getCookies();
if(Objects.isNull(cookies)){
return "你必须携带cookies信息来";
}
for(Cookie cookie : cookies){
if(cookie.getName().equals("login") && cookie.getName().equals("true")){
return "恭喜你访问成功";
}
}
return "你必须携带cookies信息来";
}
/**
* 开发一个需要携带参数才能访问的get请求
* 第一种实现方式是 url: ip:port/get/with/param?key=value&key=value
* 模拟获取商品列表 开始页数,结束的页数,一页20条数据
* */
//第一种需要携带参数访问的get请求,将参数定义在方法传参位置处,用@RequestParam关键字,在浏览器地址栏中传入
@RequestMapping(value = "/get/with/param",method = RequestMethod.GET) //请求的url
public Map
上一篇:最大子数组和
下一篇:对python选修课的感想
文章标题:Springboot 3.需求携带参数的get请求
文章链接:http://soscw.com/index.php/essay/97588.html