当我请求 asList 时,我的应用程序返回“[{},{}]”。但是当我请求 String 时,它在浏览器上显示正常。
图片:1.IDE EndPoint 2.Browser Return
端点
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
类(class)必须如下所示:
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;
}
}
关于java - 我的 Spring 应用程序无法识别我的网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60993337/