当我请求asList时,我的应用程序正在返回"[{},{}]"。但当我请求String时,它在浏览器上显示ok。
图片:1.IDE端点2.浏览器返回
端点
package br.com.devdojo.app.endpoint;
import br.com.devdojo.app.model.Student;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static java.util.Arrays.asList;
@RestController
@RequestMapping("student")
public class StudentEndPoint {
@RequestMapping(method = RequestMethod.GET, path = ("/list"))
public List<Student> listAll(){
return asList(new Student("Aluno1"), new Student("Aluno2"));
}
}
您的Student
类必须如下所示:
public class Student {
private String name;
public Student() {
}
public Student(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}