接口类定义
Controller 定义
@Controller("test")
@RequestMapping(value = "/api/rest/test")
@Api(value = "test", description = "测试相关接口", basePath = "/api/rest/test", position = 1, produces = "application/json")
public class ResourceController extends Abstract***Controller{
}
引用包
import org.springframework.stereotype.Controller;
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;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiParam;
Get 请求
@PathVariable
方式一
访问 url:
http://ip:8080/应用名/service/api/rest/test/alertsInfo/1
@RequestMapping(value = "/alertsInfo/{resId:.+}", method = RequestMethod.GET)
@ResponseBody
public List<JSONObject> getAlertsByResId(
@ApiParam(required = true, name = "resId", value = "资源ID") @PathVariable String resId) {
JSONObject obj1 = new JSONObject();
obj1.put("resId", resId);
obj1.put("alertContent", "test1");
JSONObject obj2 = new JSONObject();
obj2.put("resId"