Model view controller 在Play框架中从视图到控制器的ajax调用

Model view controller 在Play框架中从视图到控制器的ajax调用,model-view-controller,jquery,playframework,playframework-1.x,Model View Controller,Jquery,Playframework,Playframework 1.x,我是MVC和Play框架(Java)的新手。我没有将Groovy用于动态HTML,而是使用静态HTML创建了我们自己的页面,我的意思是我们没有任何Groovy表达式。这里,我有一个控制器“Customer”,它生成JSON对象,该对象必须发送到视图中的ajax调用。我尝试了render()方法,似乎没有正确使用。你能不能给我一些建议,让我从这里开始。谢谢 public static void customer(){ WordAPI objWordAPI=new WordAPI();

我是MVC和Play框架(Java)的新手。我没有将Groovy用于动态HTML,而是使用静态HTML创建了我们自己的页面,我的意思是我们没有任何Groovy表达式。这里,我有一个控制器“Customer”,它生成JSON对象,该对象必须发送到视图中的ajax调用。我尝试了render()方法,似乎没有正确使用。你能不能给我一些建议,让我从这里开始。谢谢

public static void customer(){
    WordAPI objWordAPI=new WordAPI();
    List<WordInfo> listObjWord= objWordAPI.MakeAPIObject(nSurveyId);
    JSONSerializer modelSerializer=new JSONSerializer().exclude("NSpontanity","NWordRepresentativity","NWordValue","NWordFrequency","class").rootName("Words");
    render("Application/wordcloud.html",modelSerializer.serialize(listObjWord));
  }

我认为这应该是可行的:

public static void customer(){
    WordAPI objWordAPI=new WordAPI();
    List<WordInfo> listObjWord= objWordAPI.MakeAPIObject(nSurveyId);
    JSONSerializer modelSerializer=new JSONSerializer().exclude("NSpontanity","NWordRepresentativity","NWordValue","NWordFrequency","class").rootName("Words");
    renderJSON(modelSerializer.serialize(listObjWord));
  }
publicstaticvoidcustomer(){
WordAPI objWordAPI=新WordAPI();
List listObjWord=objWordAPI.MakeAPIObject(nSurveyId);
JSONSerializer modelSerializer=new JSONSerializer().exclude(“nsontanity”、“NWordRepresentativity”、“NWordValue”、“NWordFrequency”、“class”).rootName(“Words”);
renderJSON(modelSerializer.serialize(listObjWord));
}
我以前从未使用过rootName,我通常只是做一些类似的事情:

public static void refreshNotifications()
    {
        JSONSerializer notifySerializer = new JSONSerializer().include("message","notifyId","class").exclude("*");
        List<Notification> notificationList = user.getNotifications();
        renderJSON(notifySerializer.serialize(notificationList));
    }
公共静态无效刷新通知()
{
JSONSerializer notifySerializer=新的JSONSerializer()。包括(“消息”、“通知ID”、“类”)。排除(“*”);
List notificationList=user.getNotifications();
renderJSON(notifySerializer.serialize(notificationList));
}

旁注:对于refreshNotifications,我有一个在之前运行的安全方法,用于验证和填充用户对象。

如果您有一个名为Customer的控制器和一个名为Customer的方法,则url应该是/Customer/Customer。如果您想使用url/customer,那么必须在conf/routes文件中明确定义它
public static void refreshNotifications()
    {
        JSONSerializer notifySerializer = new JSONSerializer().include("message","notifyId","class").exclude("*");
        List<Notification> notificationList = user.getNotifications();
        renderJSON(notifySerializer.serialize(notificationList));
    }