0
<bean class="myprogram.FileList">
定義。
現在我希望這個bean可以從JSP訪問。如何做到這一點?
首先想到的是在控制器方法的地方訪問bean和它放到模型
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
FileList fileList = // some code to access fileList bean
model.addAttribute("fileList", fileList);
return "home";
}
,但可能這醚不是必需的,也可以在bean的配置描述的地方?
UPDATE
答案是exposedContextBeanNames
參數。
@Autowired
private FileList fileList;
然後將其添加到模型就像你已經做了:model.addAttribute("fileList", fileList);
'$ {fileList}'? – NINCOMPOOP 2013-05-03 11:34:08
fileList應該被注入到這個代碼中! – MariuszS 2013-05-03 11:34:57