为什么最后显示的时候无法显示出数据
package com.imooc.test; import com.imooc.entity.Phone; import com.imooc.entity.PhoneList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import java.util.Collection; import java.util.Map; @Controller("myhandle2") @RequestMapping("handle2") public class Myhandle2 { @Autowired private PhoneList phoneList; @RequestMapping("phone") public String phone(PhoneList phoneMap,Map<String, Collection<Phone>> map) { for(String key:phoneMap.getPhoneMap().keySet()){ Phone phone = phoneMap.getPhoneMap().get(key); System.out.println(phone); phoneList.addPhone(phone); } map.put("phones", phoneList.getPhoneMap().values()); return "phone_list"; } }
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>手机管理</title> </head> <body> <div> <table style="padding: 5px; margin: 10px" border="1"> <th colspan="3"> <h2>手机管理</h2> </th> <tr> <td style="width: 150px">型号</td> <td style="width: 150px">品牌</td> <td style="width: 150px">价格</td> </tr> <c:forEach items="${phonesphones}" var="phone"> <tr> <td style="width: 150px">${phone.id}</td> <td style="width: 150px">${phone.name}</td> <td style="width: 150px">${phone.price}</td> </tr> </c:forEach> </table> </div> </body> </html>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <form action="/handle2/phone"> <div> <table > <tr> <td rowspan="3">手机信息1:</td> <td><input name="phoneMap['one'].id" placeholder="编号"></td> </tr> <tr><td><input name="phoneMap['one'].name" placeholder="名称"></td></tr> <tr><td><input name="phoneMap['one'].price" placeholder="价格"></td></tr> </table> </div> <div> <table > <tr> <td rowspan="3">手机信息2:</td> <td><input name="phoneMap['two'].id" placeholder="编号"></td> </tr> <tr><td><input name="phoneMap['two'].name" placeholder="名称"></td></tr> <tr><td><input name="phoneMap['two'].price" placeholder="价格"></td></tr> </table> </div> <div> <table > <tr> <td rowspan="3">手机信息3:</td> <td><input name="phoneMap['three'].id" placeholder="编号"></td> </tr> <tr><td><input name="phoneMap['three'].name" placeholder="名称"></td></tr> <tr><td><input name="phoneMap['three'].price" placeholder="价格"></td></tr> </table> </div> <input type="submit" value="提交"> </form> </body> </html>
package com.imooc.entity; import org.springframework.stereotype.Repository; import java.util.*; @Repository("PhoneList") public class PhoneList { private Map<String, Phone> phoneMap = new HashMap<String, Phone>(); public Map<String, Phone> getPhoneMap() { return phoneMap; } public void setPhoneMap(Map<String, Phone> phoneMap) { this.phoneMap = phoneMap; } public void addPhone(Phone phone){ phoneMap.put(phone.getId(), phone); } public Collection<Phone> getAll(){ return phoneMap.values(); } }
0
收起
正在回答 回答被采纳积分+1
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星