gpt4 book ai didi

java - java中如何将EL值赋给变量

转载 作者:行者123 更新时间:2023-12-02 12:09:33 24 4
gpt4 key购买 nike

我想将该对象(${categorys})分配给ArrayList

这是jsp

<%

ArrayList<Category> al =${categorys};

%>

这是 Controller

@RequestMapping(value = "/cat", method = RequestMethod.GET)
public ModelAndView getTrancationHistory() {

ArrayList<Category> allData = service.viewAllCategory();
//handle your code here...
System.out.println(allData);
for (Category allData1 : allData) {
System.out.println(allData1.getCategoryName());
}


ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("WEB-INF/views/cat");
modelAndView.addObject("categorys", allData);
return modelAndView;
}

最佳答案

您不能像在 jsp scriptlet 中那样使用 ${}。您必须手动获取它。你应该尝试这样的事情;

<%
List<Category> al = (List<Category>) request.getAttribute("categorys");
%>

<%
List<Category> al = (List<Category>) pageContext.getAttribute("categorys", pageContext.REQUEST_SCOPE);
%>

关于java - java中如何将EL值赋给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46646325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com