From 3502bd304b7fa9c5e4b3b46b8b87ce928a7a6550 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sat, 13 Sep 2025 16:46:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=B8=AAspringboot-web?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E5=85=A5=E9=97=A8=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maven-project01/pom.xml | 33 ++++++++- .../src/main/java/com/inmind/HelloWorld.java | 3 + maven-project01/src/test/java/DemoTest.java | 20 ++++++ maven-projectA/pom.xml | 9 +++ springboot-web-quickstart/.gitignore | 33 +++++++++ springboot-web-quickstart/pom.xml | 72 +++++++++++++++++++ .../SpringbootWebQuickstartApplication.java | 13 ++++ .../com/inmind/demos/web/BasicController.java | 67 +++++++++++++++++ .../demos/web/PathVariableController.java | 44 ++++++++++++ .../main/java/com/inmind/demos/web/User.java | 43 +++++++++++ .../src/main/resources/static/index.html | 6 ++ ...ringbootWebQuickstartApplicationTests.java | 13 ++++ 12 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 maven-project01/src/test/java/DemoTest.java create mode 100644 springboot-web-quickstart/.gitignore create mode 100644 springboot-web-quickstart/pom.xml create mode 100644 springboot-web-quickstart/src/main/java/com/inmind/SpringbootWebQuickstartApplication.java create mode 100644 springboot-web-quickstart/src/main/java/com/inmind/demos/web/BasicController.java create mode 100644 springboot-web-quickstart/src/main/java/com/inmind/demos/web/PathVariableController.java create mode 100644 springboot-web-quickstart/src/main/java/com/inmind/demos/web/User.java create mode 100644 springboot-web-quickstart/src/main/resources/static/index.html create mode 100644 springboot-web-quickstart/src/test/java/com/inmind/SpringbootWebQuickstartApplicationTests.java diff --git a/maven-project01/pom.xml b/maven-project01/pom.xml index 9bbe525..685f8d3 100644 --- a/maven-project01/pom.xml +++ b/maven-project01/pom.xml @@ -12,7 +12,38 @@ ch.qos.logback logback-classic - 1.5.17 + 1.2.3 + test + + + + + junit + junit + 4.12 + test + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4.1 + + jar-with-dependencies + + + + make-assembly + package + single + + + + + + \ No newline at end of file diff --git a/maven-project01/src/main/java/com/inmind/HelloWorld.java b/maven-project01/src/main/java/com/inmind/HelloWorld.java index 3b398a0..508dca6 100644 --- a/maven-project01/src/main/java/com/inmind/HelloWorld.java +++ b/maven-project01/src/main/java/com/inmind/HelloWorld.java @@ -1,7 +1,10 @@ package com.inmind; +//import org.slf4j.Logger; + public class HelloWorld { public static void main(String[] args) { System.out.println("hello maven"); +// Logger logger; } } diff --git a/maven-project01/src/test/java/DemoTest.java b/maven-project01/src/test/java/DemoTest.java new file mode 100644 index 0000000..ca37026 --- /dev/null +++ b/maven-project01/src/test/java/DemoTest.java @@ -0,0 +1,20 @@ +import org.junit.Test; +import org.slf4j.Logger; + +public class DemoTest { + + @Test + public void test(){ + System.out.println("这是单元测试1"); + } + + @Test + public void test1(){ + System.out.println("这是单元测试2"); + } + + @Test + public void test2(){ + System.out.println("这是单元测试3"); + } +} diff --git a/maven-projectA/pom.xml b/maven-projectA/pom.xml index a651478..c8561ec 100644 --- a/maven-projectA/pom.xml +++ b/maven-projectA/pom.xml @@ -13,6 +13,7 @@ 11 + ch.qos.logback @@ -20,10 +21,18 @@ 1.2.3 + com.inmind maven-projectB 1.0-SNAPSHOT + + + + junit + junit + + diff --git a/springboot-web-quickstart/.gitignore b/springboot-web-quickstart/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/springboot-web-quickstart/.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-quickstart/pom.xml b/springboot-web-quickstart/pom.xml new file mode 100644 index 0000000..ac8e2cf --- /dev/null +++ b/springboot-web-quickstart/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + com.inmind + springboot-web-quickstart + 0.0.1-SNAPSHOT + springboot-web-quickstart + springboot-web-quickstart + + 11 + UTF-8 + UTF-8 + 2.7.6 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + 11 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + com.inmind.SpringbootWebQuickstartApplication + true + + + + repackage + + repackage + + + + + + + + diff --git a/springboot-web-quickstart/src/main/java/com/inmind/SpringbootWebQuickstartApplication.java b/springboot-web-quickstart/src/main/java/com/inmind/SpringbootWebQuickstartApplication.java new file mode 100644 index 0000000..2f87536 --- /dev/null +++ b/springboot-web-quickstart/src/main/java/com/inmind/SpringbootWebQuickstartApplication.java @@ -0,0 +1,13 @@ +package com.inmind; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringbootWebQuickstartApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringbootWebQuickstartApplication.class, args); + } + +} diff --git a/springboot-web-quickstart/src/main/java/com/inmind/demos/web/BasicController.java b/springboot-web-quickstart/src/main/java/com/inmind/demos/web/BasicController.java new file mode 100644 index 0000000..3b63515 --- /dev/null +++ b/springboot-web-quickstart/src/main/java/com/inmind/demos/web/BasicController.java @@ -0,0 +1,67 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.inmind.demos.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class BasicController { + + // http://127.0.0.1:8080/hello?name=lisi + @RequestMapping("/hello") + @ResponseBody + public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) { + return "Hello " + name; + } + + // http://127.0.0.1:8080/user + @RequestMapping("/user") + @ResponseBody + public User user() { + User user = new User(); + user.setName("theonefx"); + user.setAge(666); + return user; + } + + // http://127.0.0.1:8080/save_user?name=newName&age=11 + @RequestMapping("/save_user") + @ResponseBody + public String saveUser(User u) { + return "user will save: name=" + u.getName() + ", age=" + u.getAge(); + } + + // http://127.0.0.1:8080/html + @RequestMapping("/html") + public String html() { + return "index.html"; + } + + @ModelAttribute + public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name + , @RequestParam(name = "age", defaultValue = "12") Integer age, User user) { + user.setName("zhangsan"); + user.setAge(18); + } +} diff --git a/springboot-web-quickstart/src/main/java/com/inmind/demos/web/PathVariableController.java b/springboot-web-quickstart/src/main/java/com/inmind/demos/web/PathVariableController.java new file mode 100644 index 0000000..642fd7d --- /dev/null +++ b/springboot-web-quickstart/src/main/java/com/inmind/demos/web/PathVariableController.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.inmind.demos.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author theonefx + */ +@Controller +public class PathVariableController { + + // http://127.0.0.1:8080/user/123/roles/222 + @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET) + @ResponseBody + public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) { + return "User Id : " + userId + " Role Id : " + roleId; + } + + // http://127.0.0.1:8080/javabeat/somewords + @RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET) + @ResponseBody + public String getRegExp(@PathVariable("regexp1") String regexp1) { + return "URI Part : " + regexp1; + } +} diff --git a/springboot-web-quickstart/src/main/java/com/inmind/demos/web/User.java b/springboot-web-quickstart/src/main/java/com/inmind/demos/web/User.java new file mode 100644 index 0000000..f5bdb3a --- /dev/null +++ b/springboot-web-quickstart/src/main/java/com/inmind/demos/web/User.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.inmind.demos.web; + +/** + * @author theonefx + */ +public class User { + + private String name; + + private Integer age; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } +} diff --git a/springboot-web-quickstart/src/main/resources/static/index.html b/springboot-web-quickstart/src/main/resources/static/index.html new file mode 100644 index 0000000..89bb8ba --- /dev/null +++ b/springboot-web-quickstart/src/main/resources/static/index.html @@ -0,0 +1,6 @@ + + +

hello word!!!

+

this is a html page

+ + \ No newline at end of file diff --git a/springboot-web-quickstart/src/test/java/com/inmind/SpringbootWebQuickstartApplicationTests.java b/springboot-web-quickstart/src/test/java/com/inmind/SpringbootWebQuickstartApplicationTests.java new file mode 100644 index 0000000..265a020 --- /dev/null +++ b/springboot-web-quickstart/src/test/java/com/inmind/SpringbootWebQuickstartApplicationTests.java @@ -0,0 +1,13 @@ +package com.inmind; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringbootWebQuickstartApplicationTests { + + @Test + void contextLoads() { + } + +}