今天学习了请求相应,下载了一个可以监控请求的软件postman,通过编写springboot代码,发送请求,来监测是否管用。
对于controller包中的代码
package com.itheima.controller; import jakarta.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class RequestController { // @RequestMapping("simpleParam") // public String simpleParam(HttpServletRequest request) // { // String name=request.getParameter("name"); // String ageStr=request.getParameter("age"); // int age=Integer.parseInt(ageStr); // System.out.println(name+":"+age); // return "OK"; // } @RequestMapping("simpleParam") public String simpleParam(String name,Integer age) { System.out.println(name+":"+age); return "OK"; } }
启动springboot项目,在postman软件中监测
我们在get请求中给它两个参数,就可以在控制台中查询到自己输入的信息。