我完全不懂Java。我正在尝试展示JSON数据,因此我决定使用Jackson库。但是我遇到了错误。
我正在使用
jackson-annotations-2.3.0.jar
jackson-core-2.4.2.jar
jackson-databind-2.4.2.jar
这是我的对象,其中有一个依赖项"tnStudentLocLog"
public class Student implements java.io.Serializable, WorkItem {
private int studentId;
private Date date;
private Date startTime;
private Date endtime;
private int room;
private Set tnStudentLocLog;
public Student() {
}
public Student(int studentId,Date date, int room, Date startTime, Date endtime) {
this.studentId = studentId;
this.date = date;
this.room = room;
this.startTime = startTime;
this.endtime = endtime;
}
}
UserController类:
@Controller
@RequestMapping(value="/students")
public class StudentController {
private static Logger logger = Logger.getLogger( StudentController.class);
private StudentManagerDelegate studentDelegate;
public StudentController() throws Exception
{
studentDelegate= new StudentManagerDelegate(ServiceType.LOCAL);
}
/********* GET ALL STUDENTS ************/
@RequestMapping(method=RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody SuccessResponse<List<Student>> getAllStudents() throws Exception {
Map<String,List<Student>> studentsMap = new HashMap<String,List<Student>>();
SuccessResponse<List<Student>> resp = new SuccessResponse<List<Student>>();
resp.list = studentDelegate.load();
return resp;
}
在这里,我得到了正确的结果。但是,“studentId”:2像下面这样循环。
{"max":"30","list":[{"studentId":2,"date":1339327730000,"startTime":1339327806000,"endtime":1339329470000,"room":0,"tnStudentLocLog":
[{"id":"studentId":2,"inTime":1339327872000},"sequenceId":2,"outTime":1339327967000,"Student":{"studentId":2,"date":1339327730000,"startTime":1339327806000,"endtime":1339329470000,"tnStudentLocLog":[{"id":{"studentId":2,"room":10,"inTime":1339327872000},"sequenceId":2,"outTime":1339327967000,"Student":{"studentId":2,"date":1339327730000,"startTime":1339327806000,"endtime":1339329470000,"tnStudentLocLog":[{"id":.......
但是,当我输入“/students/4”时,URL显示正确。 我不知道到底发生了什么。我看到很多帖子,它们正在更改Jackson核心版本、注释。 但是,在我的情况下,那并没有起作用。
提前感谢您的帮助。