restful支持@PathVariable

This commit is contained in:
tanghc
2019-10-09 18:27:43 +08:00
parent caaff21876
commit 0cc8c0b991
6 changed files with 83 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ package com.gitee.sop.storyweb.controller;
import com.gitee.sop.servercommon.util.UploadUtil;
import lombok.Data;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -14,6 +15,7 @@ import java.util.Collection;
/**
* 传统web开发实例
*
* @author tanghc
*/
@RestController
@@ -72,6 +74,15 @@ public class TraditionalWebappController {
return food;
}
// http://localhost:2222/food/get/3 本地
// http://localhost:8081/rest/food/get/3 网关访问
@RequestMapping("/get/{id}")
public Food getById(@PathVariable("id") Integer id) {
Food food = new Food();
food.setId(id);
return food;
}
@Data
public static class Food {
private Integer id;