spring 3未在jsp中渲染模型 [英] spring 3 not rendering model in jsp

查看:71
本文介绍了spring 3未在jsp中渲染模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Spring 3不使用表达式语言在jsp中呈现我的模型感到有些失望,我不得不承认我不明白为什么.如果有人可以帮助我理解为什么我无法使其正常运行,那将是非常棒的.

I am a bit disapointed concerning Spring 3 not rendering my model in a jsp using Expression Language and I have to admit that I dont understand why. If anyone could help me understanting why I can't make it work it will be really great.

这是我的上下文:

我的控制器有一个方法(由我的客户端的ajax调用)返回一个jsp片段:

My controller have a method (called by ajax from my client) returning a jsp fragment:

@RequestMapping(value = "/datagrid/getGoatCard", method = RequestMethod.POST)
public String getGoatCard(@RequestParam Long id,
        @ModelAttribute("goat") Goat goat) {
    goat = goatDataService.findGoatById(id);
    return "goatCard";
}

我使用requestParam调用此方法,该方法允许休眠模式检索所需的Bean(该模型包含所有需要的数据,已经检查过).

I call this method with a requestParam allowing hibernate to retrieve the desired Bean (the model contains all the requiered data, it has been checked).

然后,该方法重新运行一个名为"goatCard"的jsp;这是jsp代码:

Then this method retruns a jsp named "goatCard"; here's the jsp code:

<input name="goat.goatName" type="hidden" value="${goat.goatName}"/>

(这不是整个页面的代码,如果提供太多代码,这将不容易阅读.我的jsp包含JQuery easyui和highcharts javaScript库)

(this isn't the whole page code, cause this won't be easy to read if too many code is presented. My jsp contains JQuery easyui and highcharts javaScript librairies)

尽管注释@ModelAttribute("goat")将名为"goat"的模型链接到我的jsp,允许使用EL渲染模型,但事实并非如此.

I though that the annotation @ModelAttribute("goat") linked the model called "goat" to my jsp allowing to render the model using EL but it doesn't seem so.

有人有什么主意吗,也许只是我做错了一点小事,但我看不到哪一个!!!

Does anybody have any idea, perhaps it just a little thing that I did wrong but I don't see which one!!!!

推荐答案

@ModelAttribute 用于检索表单模型,而不是设置为在JSP中显示. 如果需要在JSP中显示数据,则必须首先将数据添加到模型中.

@ModelAttribute is used for retrieving form model rather than setting to be displayed in JSP. If you need to display data in JSP, you have to add the data into Model first.

@RequestMapping(value = "/datagrid/getGoatCard", method = RequestMethod.POST)
public ModelAndView getGoatCard(@RequestParam Long id) {
    ModelAndView mv = new ModelAndView("goatCard");
    Goat goat = goatDataService.findGoatById(id);
    mv.addObject("goat",goat);
    return mv;
}

然后可以在JSP文件中使用山羊. 顺便说一句,要检索数据,最好使用 RequestMethod.GET .

And then goat is available in JSP file. By the way, for retrieving data, better to use RequestMethod.GET.

这篇关于spring 3未在jsp中渲染模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆