【发布时间】:2011-05-21 13:20:43
【问题描述】:
我正在使用 Spring MVC,我想做一个 AJAX 调用来获取带有一组 Person 对象的 JSON 消息。 我有这个 jQuery 代码:
$(document).ready(function() {
getAllPersons();
});
function getAllPersons() {
$.getJSON("person/allpersons", function(data) {
alert(data);
});
}
个人/所有人(REST URL)调用RequestMapping:
@RequestMapping(value="/allersons", method=RequestMethod.GET)
public @ResponseBody ??? ???() {
???
}
我实施了一项服务来获取所有人员:
public interface IPersonService {
public Person addPerson(Person p);
...
public Set<Person> getAllPersons();
}
如何调用此服务?那么我必须放置什么而不是 ???
我尝试了几种类似的方法,但在我的 Eclipse IDE 中出现错误:
public @ResponseBody <Set>Person getSomething() {
Set<Person> persons = IPersonService.getAllPersons();
return persons;
}
错误/警告:
The type parameter Set is hiding the type Set<E>
Cannot make a static reference to the non-static method getAllPersons() from the type IPersonService
The type Set is not generic; it cannot be parameterized with arguments <Person>
有什么建议吗?
在此先感谢您并致以最诚挚的问候。
【问题讨论】:
标签: java ajax json spring spring-mvc