为什么最后显示的时候无法显示出数据

为什么最后显示的时候无法显示出数据

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();
    }
}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
提问者 慕村4575073 2019-10-19 20:09:40

这个问题解决了jsp循环的值写错,但是为什么只要输入的数据不完整就会报404错误http://img1.sycdn.imooc.com//climg/5daafcd0092a228809780390.jpg

  • 同学你好,这里报的是400错误哦,400错误通常代表这个请求是不符合规定的,请求参数有误,所以需要按照规定输入完整的数据哦。如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
    2019-10-20 11:31:30
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师