我在SpringBoot中使用JSTL循环并获取Beans中的所有项目。但是当我得到结果时,我收到了一个错误:
javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
型号:
@Entity
public class Manufacturer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
private String content;
// Get and Set
}
存储库类:
public interface ManufacturerRepository extends CrudRepository<Manufacturer, Integer> {
}
服务类:
public interface ManufacturerService {
Iterable<Manufacturer> listAllManufacturers();
}
服务Impl类:
@Service
public class ManufacturerServiceImpl implements ManufacturerService {
private ManufacturerRepository manufacturerRepository;
@Autowired
public void setManufacturerRepository(ManufacturerRepository manufacturerRepository) {
this.manufacturerRepository = manufacturerRepository;
}
@Override
public Iterable<Manufacturer> listAllManufacturers() {
return manufacturerRepository.findAll();
}
}
控制器类:
@Controller
@Component
@Scope("prototype")
public class ManagementManufacturerController {
private ManufacturerService manufacturerService;
@Autowired
public void setManufacturerService(ManufacturerService manufacturerService) {
this.manufacturerService = manufacturerService;
}
@RequestMapping(value = "/manufacturer", method = RequestMethod.GET)
public String list(Model model, HttpServletRequest request, HttpServletResponse response) {
model.addAttribute("manufacturers", manufacturerService.listAllManufacturers());
return "manageManufacturer";
}
}
JSP:
<c:forEach var="renter" items="${manufacturers}" varStatus="status">
<c:out value="${renter.id}" />
<c:out value="${renter.name}" />
<c:out value="${renter.content}" />
</c:forEach>
记录消息:
Stacktrace:] with root cause
javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:274)
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:238)
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:155)
at javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:256)
at org.apache.jsp.WEB_002dINF.views.manageManufacturer_jsp._jspx_meth_c_005fforEach_005f0(manageManufacturer_jsp.java:107)
at org.apache.jsp.WEB_002dINF.views.manageManufacturer_jsp._jspService(manageManufacturer_jsp.java:74)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
我尝试过更改属性名称: items =“$ {manufacturers}”但是同样的错误,如何解决问题?谢谢