main v3.0.0
liangjiajie 1 year ago
parent 94dab49cd1
commit dc8d2397c8

@ -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 <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
@ -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";
}

@ -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 <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
@ -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;

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

@ -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");
}
}

Loading…
Cancel
Save