diff --git a/springboot-web-quickstart/src/main/resources/application.properties b/springboot-web-quickstart/src/main/resources/application.properties index bb3972c..f46cce5 100644 --- a/springboot-web-quickstart/src/main/resources/application.properties +++ b/springboot-web-quickstart/src/main/resources/application.properties @@ -1,2 +1,2 @@ spring.application.name=springboot-web-quickstart -server.port=8083 \ No newline at end of file +#server.port=8083 \ No newline at end of file diff --git a/springboot-web-req-resp/.gitignore b/springboot-web-req-resp/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/springboot-web-req-resp/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/springboot-web-req-resp/.mvn/wrapper/maven-wrapper.properties b/springboot-web-req-resp/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..5291372 --- /dev/null +++ b/springboot-web-req-resp/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.15/apache-maven-3.9.15-bin.zip diff --git a/springboot-web-req-resp/pom.xml b/springboot-web-req-resp/pom.xml new file mode 100644 index 0000000..5dfa72a --- /dev/null +++ b/springboot-web-req-resp/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.5.14 + + + com.inmind + springboot-web-req-resp + 0.0.1-SNAPSHOT + springboot-web-req-resp + springboot-web-req-resp + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java b/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java new file mode 100644 index 0000000..8da9815 --- /dev/null +++ b/springboot-web-req-resp/src/main/java/com/inmind/SpringbootWebReqRespApplication.java @@ -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); + } + +} diff --git a/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java b/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java new file mode 100644 index 0000000..8eec2bd --- /dev/null +++ b/springboot-web-req-resp/src/main/java/com/inmind/controller/RequestController.java @@ -0,0 +1,32 @@ +package com.inmind.controller; + +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +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:"+name+",age:"+age); + return "OK"; + }*/ + + + //springboot方式获取请求参数 + @RequestMapping( "/simpleParam") + //@RequestParam(name = "name" ) 的作用是从请求对象中获取name属性值,将值赋给username变量 + public String simpleParam(@RequestParam(name = "name",required = false ) String username, Integer age){ + System.out.println("name:"+username+",age:"+age); + return "OK"; + } + +} diff --git a/springboot-web-req-resp/src/main/resources/application.properties b/springboot-web-req-resp/src/main/resources/application.properties new file mode 100644 index 0000000..b511c3b --- /dev/null +++ b/springboot-web-req-resp/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=springboot-web-req-resp diff --git a/springboot-web-req-resp/src/test/java/com/inmind/SpringbootWebReqRespApplicationTests.java b/springboot-web-req-resp/src/test/java/com/inmind/SpringbootWebReqRespApplicationTests.java new file mode 100644 index 0000000..f369f2a --- /dev/null +++ b/springboot-web-req-resp/src/test/java/com/inmind/SpringbootWebReqRespApplicationTests.java @@ -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() { + } + +}