请求-简单参数获取

This commit is contained in:
2025-09-20 15:50:12 +08:00
parent fafc2f1126
commit 2c2bbd2c95
10 changed files with 343 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.inmind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootWebReqRespApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootWebReqRespApplication.class, args);
}
}

View File

@@ -0,0 +1,33 @@
package com.inmind.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@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";
}*/
//springboot接收简单参数
/*
@RequestParam
1.当请求参数与方法形参名不一致时那使用该注解进行映射name属性
2.required属性默认是true当前参数成为必须参数可以修改为flase当前参数可选参数
*/
@RequestMapping("/simpleParam")
public String simpleParam(@RequestParam(name = "name",required = false) String username, Integer age){
System.out.println(username +" "+ age);
return "ok";
}
}

View File

@@ -0,0 +1,6 @@
<html>
<body>
<h1>hello word!!!</h1>
<p>this is a html page</p>
</body>
</html>

View File

@@ -0,0 +1,13 @@
package com.inmind;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringbootWebReqRespApplicationTests {
@Test
void contextLoads() {
}
}