Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java springmvc-AJAX/JSON-ResponseBody->;呼叫服务_Java_Ajax_Json_Spring_Spring Mvc - Fatal编程技术网

Java springmvc-AJAX/JSON-ResponseBody->;呼叫服务

Java springmvc-AJAX/JSON-ResponseBody->;呼叫服务,java,ajax,json,spring,spring-mvc,Java,Ajax,Json,Spring,Spring Mvc,我正在使用SpringMVC,我想通过一个AJAX调用来获取一条带有一组Person对象的JSON消息。 我有这个jQuery代码: $(document).ready(function() { getAllPersons(); }); function getAllPersons() { $.getJSON("person/allpersons", function(data) { alert(data); }); } person/allperson

我正在使用SpringMVC,我想通过一个AJAX调用来获取一条带有一组Person对象的JSON消息。 我有这个jQuery代码:

$(document).ready(function() {
    getAllPersons();
});
function getAllPersons() {
    $.getJSON("person/allpersons", function(data) {
        alert(data);
    });
}
person/allpersons(REST URL)调用RequestMapping:

@RequestMapping(value="/allersons", method=RequestMethod.GET)
public @ResponseBody ??? ???() {
    ???
}
我实施了一项服务,以让所有人:

public interface IPersonService {
    public Person addPerson(Person p);
    ...
    public Set<Person> getAllPersons();
}
公共接口IPersonService{
公众人物addPerson(人物p);
...
公共设置getAllPersons();
}
我该怎么称呼这项服务?那个么我应该放什么来代替

我尝试了几种类似的方法,但在Eclipse IDE中出现了错误:

public @ResponseBody <Set>Person getSomething() {
    Set<Person> persons = IPersonService.getAllPersons();
    return persons;
}
public@ResponseBody Person getSomething(){
Set persons=IPersonService.getAllPersons();
返回人员;
}
错误/警告:

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>
类型参数集正在隐藏类型集
无法从类型IPersonService对非静态方法getAllPersons()进行静态引用
类型集不是泛型的;不能使用参数对其进行参数化
有什么建议吗


提前感谢并致以最良好的问候。

在您的方法中,人是错的,应该设置

public @ResponseBody Set<Person> getSomething() {
    Set<Person> persons = new IPersonServiceImpl().getAllPersons();
    return persons;
}

}

我更改了它,在服务调用中又出现了一个错误:无法从IPersonService类型对非静态方法getAllPersons()进行静态引用。该服务方法已经实现,我已经将其用于AdobeFlex前端和BlazeDS。但是我没有让它在我的Java后端中运行。(公共类PersonServiceImpl实现IPersonService…它存在…)谢谢,现在我收到错误消息:IPersonServiceImpl无法解析为类型。接口和实现的结构是正确的(与您编写的相同)。哦,对不起,调用实现是可行的。但是调用实现而不是服务不是错误的吗?
public class IPersonServiceImpl implements IPersonService{
    public Set<Person> getAllPersons(){
     -- Your Business Logic
    }
    public Person addPerson(Person p){
     -- Your Business Logic
    }
}