点o 2024-05-24 00:29 采纳率: 57.1%
浏览 12

使用c:forEach出现页面空白,没有数据

controller

package com.hnjdxy.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.hnjdxy.pojo.scheme;
import com.hnjdxy.service.schemeService;


@Controller
public class schemeController<UserInfo> {
    
@Autowired
private schemeService schemservice;
@RequestMapping("/findAll")
public ModelAndView findAll() {
    List<scheme> list=schemservice.findAll();
    ModelAndView mav=new ModelAndView();
    mav.setViewName("listOffer.jsp");
    mav.addObject("list",list);
    return mav;
    
}
@RequestMapping("/findUserByid")
public  ModelAndView getUserById(HttpServletRequest request){
    ModelAndView mav=new ModelAndView();
    String bpl_guid=request.getParameter("bpl_guid");
    scheme scheme=schemservice.findUserByid(bpl_guid);
    mav.setViewName("updateOffer.jsp");
    mav.addObject("scheme",scheme);
    return mav;
}

@RequestMapping("/update")
public ModelAndView update(HttpServletRequest request) {
    ModelAndView mav=new ModelAndView();
    String bpl_guid=request.getParameter("bpl_guid");
    String unit_name=request.getParameter("unit_name");
    String period1_area=request.getParameter("period1_area");
    String per_sum_area=request.getParameter("per_sum_area");
    String inputer=request.getParameter("inputer");
    scheme s=new scheme();
    s.setBpl_guid(bpl_guid);
    s.setUnit_name(unit_name);
    s.setPeriod1_area(period1_area);
    s.setPeriod1_area(period1_area);
    s.setInputer(inputer);
     schemservice.update(s);
        mav.setViewName("/findAll");
        return mav;
       }

}


mapper

package com.hnjdxy.dao;

import java.util.List;

import com.hnjdxy.pojo.scheme;

public interface schemeMapper {
public List<scheme> findAll();
public int update(scheme scheme);
public scheme findUserByid(String bpl_guid);
}


xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
   PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
   "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnjdxy.dao.schemeMapper">
    <select id="findAll" resultType="com.hnjdxy.pojo.scheme">
select * from t_land_offer_scheme
    </select>
        <update id="update" parameterType="com.hnjdxy.pojo.scheme" >
        UPDATE t_land_offer_scheme SET unit_name=#{unit_name},
        period1_area=#{period1_area}, per_sum_area=#{per_sum_area},inputer=#{inputer}
        WHERE bpl_guid=#{bpl_guid}
    </update>
<select id="findUserByid" resultType="com.hnjdxy.pojo.scheme">
select * from t_land_offer_scheme where bpl_guid=#{bpl_guid}


</select>




</mapper>


service

package com.hnjdxy.service;

import java.util.List;

import com.hnjdxy.pojo.scheme;

public interface schemeService {
    public List<scheme> findAll();
    public int update(scheme scheme);
    public scheme findUserByid(String bpl_guid);
}


serviceimpl

package com.hnjdxy.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hnjdxy.dao.schemeMapper;
import com.hnjdxy.pojo.scheme;
@Service
public class schemeServcieImpl implements schemeService {

@Autowired
private schemeMapper schememapper;
    @Override
    public List<scheme> findAll() {
        // TODO Auto-generated method stub
        return schememapper.findAll();
    }

    @Override
    public int update(scheme scheme) {
        // TODO Auto-generated method stub
        return schememapper.update(scheme);
    }

    @Override
    public scheme findUserByid(String bpl_guid) {
        // TODO Auto-generated method stub
        return schememapper.findUserByid(bpl_guid);
    }

    

    
}


jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>

<body>
<table width="495" border="1" style="border-collapse:collapse">
 <tr>
    <td width="72"><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000"> 说明书序号</font> </div></td>
    <td width="72"><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000"> 单位名称 </font></div></td>
    <td width="72"><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000" > 第一期面积</font></div></td>
    <td width="95"><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">本期用地总面积</font></div> </td>
    <td width="46"><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">填表人</font></div></td>
    <td width="105"><div align="center"></div></td>
  </tr>  
    
  <tr>
  <c:forEach items="${list}" var="list">
    <td><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">${list.bpl_guid}</font></div></td>
    <td><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">${list.unit_name}</font> </div></td>
    <td><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">${list.period1_area}</font></div></td>
    <td><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">${list.per_sum_area}</font></div></td>
    <td><div align="center"><font color="#3074A2" style="font-size:9pt;color:#000000">${list.inputer}</font></div></td>
    <td>
    <input type="button" name="bt1" value="删除"> 
    <a href="${pageContext.request.contextPath }/findUserByid?${lists.bpl_guid}"><input type="button" name="bt2" value="修改" ></a>
    </td>
  </tr>  
  </c:forEach>
</table>
</body>
</html>



修改jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>添加供地方案

</title>
</head>

<body>
<script language="javascript">

</script>


<table width="340" border="0">
<tr><td width="553"><form action="${pageContext.request.contextPath }/update" method="post" name="form1" onSubmit="return check()">
   <c:forEach items="${list}" var="lists">
  <table width="290" height="70" border="1" align="center" style="border-collapse:collapse">
           <tr>
            <!--  01 -->
            <td width="131" height="9"><div align="right">
                <font color="#3074A2" style="font-size: 9pt; color: #000000">说明书序号</font>
            </div></td>
            <td width="188"><input name="bpl_guid" type="text" id="bpl_guid" size="20" value="${lists.bpl_guid}" readonly="true"></td>
        </tr>
        <tr>
            <!-- 蟠龙欣苑 -->
            <td width="131" height="4"><div align="right">
                <font color="#3074A2" style="font-size: 9pt; color: #000000">单位名称</font>
            </div></td>
            <td><input name="unit_name" type="text" id="unit_name" size="20" value="${lists.unit_name}"><span style="color: red;">*</span></td>
        </tr>
        <tr>
            <!-- 20公顷 -->
            <td width="131" height="29"><div align="right">
                <font color="#3074A2" style="font-size: 9pt; color: #000000">第一期面积</font>
            </div></td>
            <td><input name="period1_area" type="text" id="period1_area" size="20" value="${lists.period1_area}"></td>
        </tr>
        <tr>
            <!-- 110公顷 -->
            <td width="131" height="4"><div align="right">
                <font color="#3074A2" style="font-size: 9pt; color: #000000">本期用地总面积</font>
            </div></td>
            <td><input name="per_sum_area" type="text" id="per_sum_area" size="20" value="${lists.per_sum_area}"></td>
        </tr>
        <tr>
            <!-- 方颜 -->
            <td height="4"><div align="right">
                <font color="#3074A2" style="font-size: 9pt; color: #000000">填表人</font>
            </div></td>
            <td><input name="inputer" type="text" id="inputer" size="20" value="${lists.inputer}"></td>
        </tr>
        <tr>
            <td width="131" height="4"><div align="right"></div></td>
            <td><input type="submit" name="bt1" value="确定"></td>
        </tr>
 </c:forEach>
  </table>
</form></td>
</tr>
</table>
</body>
</html>



为什么我运行出来是空白的,点击修改就连表格都没有,

img

img

  • 写回答

4条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-05-24 00:29
    关注

    引自免费微信小程序:皆我百晓生

    根据您提供的代码和描述,看起来您的应用应该展示一个包含列表信息的页面,并且用户可以对单个条目进行编辑。目前的问题在于,您在JSP页面上使用的<c:forEach>标签可能存在一些错误。

    首先,让我们检查一下JSP页面上的<c:forEach>标签。在原始的JSP代码中,您有一个错误地定义了循环变量名。在遍历时,您使用了var="list",但在循环体内部,您又使用了lists。这会导致找不到正确的对象。下面是修复后的JSP代码:

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>添加供地方案</title>
    </head>
    
    <body>
    <script language="javascript">
    
    </script>
    
    <table width="340" border="0">
    <tr><td width="553"><form action="${pageContext.request.contextPath }/update" method="post" name="form1" onSubmit="return check()">
       <c:forEach items="${list}" var="list">
      <table width="290" height="70" border="1" align="center" style="border-collapse:collapse">
               <tr>
                <!--  01 -->
                <td width="131" height="9"><div align="right">
                    <font color="#3074A2" style="font-size: 9pt; color: #000000">说明书序号</font>
                </div></td>
                <td width="188"><input name="bpl_guid" type="text" id="bpl_guid" size="20" value="${list.bpl_guid}" readonly="true"></td>
            </tr>
            <tr>
                <!-- 蟠龙欣苑 -->
                <td width="131" height="4"><div align="right">
                    <font color="#3074A2" style="font-size: 9pt; color: #000000">单位名称</font>
                </div></td>
                <td><input name="unit_name" type="text" id="unit_name" size="20" value="${list.unit_name}"><span style="color: red;">*</span></td>
            </tr>
            <tr>
                <!-- 20公顷 -->
                <td width="131" height="29"><div align="right">
                    <font color="#3074A2" style="font-size: 9pt; color: #000000">第一期面积</font>
                </div></td>
                <td><input name="period1_area" type="text" id="period1_area" size="20" value="${list.period1_area}"></td>
            </tr>
            <tr>
                <!-- 110公顷 -->
                <td width="131" height="4"><div align="right">
                    <font color="#3074A2" style="font-size: 9pt; color: #000000">本期用地总面积</font>
                </div></td>
                <td><input name="per_sum_area" type="text" id="per_sum_area" size="20" value="${list.per_sum_area}"></td>
            </tr>
            <tr>
                <!-- 方颜 -->
                <td height="4"><div align="right">
                    <font color="#3074A2" style="font-size: 9pt; color: #000000">填表人</font>
                </div></td>
                <td><input name="inputer" type="text" id="inputer" size="20" value="${list.inputer}"></td>
            </tr>
            <tr>
                <td width="131" height="4"><div align="right"></div></td>
                <td><input type="submit" name="bt1" value="确定"></td>
            </tr>
     </c:forEach>
      </table>
    </form></td>
    </tr>
    </table>
    </body>
    </html>
    

    这段代码应该修复循环变量名不一致的问题。同时,我注意到在修改后的JSP页面中,所有的表单元素都放在了一个大的循环里,这意味着每个数据项都会有自己的提交按钮。为了正确处理更新请求,您可能需要为整个表格提供一个单独的提交按钮,而不是每个项目都有一个。

    确保您的控制器方法将模型属性传递给正确的视图(例如findAll方法中的mav.setViewName("listOffer.jsp"))。如果问题仍然存在,请检查网络日志或控制台输出,看是否有任何与数据获取、渲染或提交相关的异常。此外,确认数据库连接正常并且数据确实被查询到了。

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 5月24日

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表