JavaSpring框架:应用程序上下文赢得';t集性质
问题是: 当我在chrome中运行它时,content div不显示图像字符串(在收据对象的应用程序上下文中设置) ItemGroup类有一个项目列表 收据是抽象类Item的一个子类 这是我在netbeans中的代码: applicationContext.xml:JavaSpring框架:应用程序上下文赢得';t集性质,java,html,spring,inheritance,Java,Html,Spring,Inheritance,问题是: 当我在chrome中运行它时,content div不显示图像字符串(在收据对象的应用程序上下文中设置) ItemGroup类有一个项目列表 收据是抽象类Item的一个子类 这是我在netbeans中的代码: applicationContext.xml: <bean id="receipt1" class="domain.receipts.Receipt" > <property name="id" value="1"/> &
<bean id="receipt1" class="domain.receipts.Receipt" >
<property name="id" value="1"/>
<property name="image" value="Images/receipt.png"/>
</bean>
<bean id="receipts" class="domain.ItemGroup">
<property name="items">
<list>
<ref bean="receipt1"/>
</list>
</property>
<property name="image" value="/Images/klantenkaart.png"/>
</bean>
调试这篇文章可能会发现一些东西 您是否调试控制器以验证参数是否正确放入模型?这至少可以帮助您缩小是应用程序上下文还是model/jsp的责任范围。是的,但很难说
@Controller
public class HomeController
{
private ItemGroupService itemGroupService;
@Autowired
private ItemGroup receipts;
@Autowired
private ItemGroup shoppinglists;
@Autowired
private ItemGroup cards;
@Autowired
public HomeController(ItemGroupService ItemGroupServiceImpl)
{
this.itemGroupService=ItemGroupServiceImpl;
}
public List<Item> getReceipts()
{
return receipts.getItems();
}
@RequestMapping(value = {"/index"},method = RequestMethod.GET)
public String showHomePage(Model model)
{
model.addAttribute("itemGroup", new ItemGroup());
return "index";
}
@RequestMapping(value = {"/index"},method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("itemGroup") ItemGroup itemGroup, Model model)
{
if(itemGroup.getName().equals("receipts"))
{
model.addAttribute("itemList",receipts.getItems());
}
else if(itemGroup.getName().equals("cards"))
{
model.addAttribute("itemList",cards.getItems());
}
return "index";
}
}
<div id="header">
<table>
<tr>
<form:form method="POST" action="index.htm" modelAttribute="itemGroup">
<form:input path="name" type="hidden" value="receipts" />
<input type="image" src="Images/receipt.png" height="150px" width="180px" alt="Submit" value="receipts">
</form:form>
<form:form method="POST" action="index.htm" modelAttribute="itemGroup">
<form:input path="name" type="hidden" value="shoppinglists" />
<input type="image" src="Images/shoppinglist.png" height="150px" width="180px" alt="Submit" value="shoppinglists">
</form:form>
<form:form method="POST" action="index.htm" modelAttribute="itemGroup">
<form:input path="name" type="hidden" value="cards" />
<input type="image" src="Images/loyalitycard.png" height="150px" width="180px" alt="Submit" value="cards">
</form:form>
<form:form method="POST" action="index.htm" modelAttribute="itemGroup">
<form:input path="name" type="hidden" value="vouchers" />
<input type="image" src="Images/voucher.png" height="150px" width="180px" alt="Submit" value="vouchers">
</form:form>
</tr>
</table>
</div>
<div id="leftcol">
</br>
</div>
<div id="content">
</br>
<h1> ${itemList}</h1>
<c:forEach items="${itemList}" var="prod" >
<h1>${prod.image}<h1>
</c:forEach>
</div>
public abstract class Item
{
private int id;
private String barcode;
private Date creationDate;
protected String image;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
model.addAttribute("itemList",cards.getItems());