1、idea IDE可以作为http请求的工具【尤其是post】
路径菜单栏 tools –>Test Restful Web Service
2、spring可以将输入和输出换成json 给 request和response传递出去,
所以没必要将接口的参数写成request
package com.alisa;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/my")
public class MyController {
// 可以运行
@RequestMapping(value = "/student", method = { RequestMethod.GET })
public Student testReturnStudent() {
Student student = new Student();
student.setId(12);
student.setName("alisa");
return student;
}
// 可以运行
@RequestMapping(value = "/studentPost", method = { RequestMethod.POST })
public Student testReturnPostStudent() {
Student student = new Student();
student.setId(12);
student.setName("alisa");
return student;
}
// 可以运行
@RequestMapping(value = "/params", method = { RequestMethod.GET })
public Student testParamsStudent(Student student) {
return student;
}
// 可以运行
@RequestMapping(value = "/paramsPost", method = { RequestMethod.POST })
public Student testParamsPostStudent(Student student) {
return student;
}
}