diff --git a/src/main/java/com/ljj/myspringboot/demos/web/BasicController.java b/src/main/java/com/ljj/myspringboot/demos/web/BasicController.java index 3aa5c70..920c948 100644 --- a/src/main/java/com/ljj/myspringboot/demos/web/BasicController.java +++ b/src/main/java/com/ljj/myspringboot/demos/web/BasicController.java @@ -17,10 +17,7 @@ package com.ljj.myspringboot.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; +import org.springframework.web.bind.annotation.*; /** * @author theonefx @@ -29,14 +26,14 @@ import org.springframework.web.bind.annotation.ResponseBody; public class BasicController { // http://127.0.0.1:8080/hello?name=lisi - @RequestMapping("/hello") + @GetMapping("/hello") @ResponseBody public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) { return "Hello v2.0.0 " + name; } // http://127.0.0.1:8080/user - @RequestMapping("/user") + @GetMapping("/user") @ResponseBody public User user() { User user = new User(); @@ -46,14 +43,14 @@ public class BasicController { } // http://127.0.0.1:8080/save_user?name=newName&age=11 - @RequestMapping("/save_user") + @GetMapping("/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") + @GetMapping("/html") public String html() { return "index.html"; } diff --git a/src/main/java/com/ljj/myspringboot/demos/web/PathVariableController.java b/src/main/java/com/ljj/myspringboot/demos/web/PathVariableController.java index 1a97291..7c804cc 100644 --- a/src/main/java/com/ljj/myspringboot/demos/web/PathVariableController.java +++ b/src/main/java/com/ljj/myspringboot/demos/web/PathVariableController.java @@ -17,10 +17,7 @@ package com.ljj.myspringboot.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; +import org.springframework.web.bind.annotation.*; /** * @author theonefx @@ -29,14 +26,14 @@ import org.springframework.web.bind.annotation.ResponseBody; public class PathVariableController { // http://127.0.0.1:8080/user/123/roles/222 - @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET) + @GetMapping(value = "/user/{userId}/roles/{roleId}") @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) + @GetMapping(value = "/javabeat/{regexp1:[a-z-]+}") @ResponseBody public String getRegExp(@PathVariable("regexp1") String regexp1) { return "URI Part : " + regexp1; diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html deleted file mode 100644 index 89bb8ba..0000000 --- a/src/main/resources/static/index.html +++ /dev/null @@ -1,6 +0,0 @@ - - -

hello word!!!

-

this is a html page

- - \ No newline at end of file diff --git a/src/test/java/com/ljj/myspringboot/MyspringbootApplicationTests.java b/src/test/java/com/ljj/myspringboot/MyspringbootApplicationTests.java index e251e95..a1cd91e 100644 --- a/src/test/java/com/ljj/myspringboot/MyspringbootApplicationTests.java +++ b/src/test/java/com/ljj/myspringboot/MyspringbootApplicationTests.java @@ -1,13 +1,19 @@ package com.ljj.myspringboot; +import com.ljj.myspringboot.demos.web.User; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import static org.springframework.test.util.AssertionErrors.assertEquals; + @SpringBootTest class MyspringbootApplicationTests { + @Test void contextLoads() { + assertEquals("正确",1,"1==1"); } }