请求-简单参数获取
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
@@ -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";
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>hello word!!!</h1>
|
||||
<p>this is a html page</p>
|
||||
</body>
|
||||
</html>
|
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user