正在回答 回答被采纳积分+1
package com.work.oa.controller;
import com.work.oa.biz.DepartmentBiz;
import com.work.oa.entity.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Iterator;
import java.util.Map;
/**
* @ClassName DepartmentController
* @Description TODO
* @Auther wangyang
* @Date 2019/2/13 20:17
* @Version 1.0
**/
@Controller("departmentController")
@RequestMapping("/department")
public class DepartmentController {
@Autowired
public DepartmentBiz departmentBiz;
@RequestMapping("/list")
public String list(Map<String,Object> map){
map.put("list",departmentBiz.getAll());
Iterator<Map.Entry<String,Object>> it=map.entrySet().iterator();
while(it.hasNext()){
Map.Entry<String,Object> entry=it.next();
System.out.println(entry.getValue());
}
return "department_list";
}
@RequestMapping("/to_add")
public String toAdd(Map<String,Object> map){
map.put("department",new Department());
return "department_add";
}
@RequestMapping("/add")
public String add(Department department){
departmentBiz.add(department);
return "redirect:list";
}
@RequestMapping(value = "/to_update",params = "sn")
public String toUpdate(String sn,Map<String,Object> map){
map.put("department",departmentBiz.get(sn));
return "department_update";
}
@RequestMapping("/update")
public String update(Department department){
departmentBiz.edit(department);
return "redirect:list";
}
@RequestMapping(value = "/remove",params = "sn")
public String remove(String sn,Map<String,Object> map){
departmentBiz.remove(sn);
return "redirect:list";
}
}
DepartmentController.java的代码
不需要再添加basePath,感觉你的数据应该没有返回到department_list.jsp中,请问同学是在DepartmentController的代码中打印list集合的吗?如果不是,建议在下图list方法中打印一下list集合,看看是否有数据,或者将DepartmentController中的代码粘贴一下,方便我们为你进行调试,祝学习愉快~
你好同学,举个例子,在top.jsp中,可以在路径前加上basePath来表示。譬如下图写法,
<img src="<%=basePath%>/assets/img/avatars/5.jpg" alt="avatar" class="mw30 br64">
而basePath的代码可以按下图这种写法添加到页面顶端呢,如果还有问题同学可以继续提问哦,祝学习愉快~
<%--
Created by IntelliJ IDEA.
User: 12640
Date: 2019/2/13
Time: 20:26
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<jsp:include page="top.jsp"/>
<section id="content" class="table-layout animated fadeIn">
<div class="tray tray-center">
<div class="content-header">
<h2> 部门列表 </h2>
<p class="lead"></p>
</div>
<div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;">
<div class="panel heading-border">
<div class="panel-menu">
<div class="row">
<div class="hidden-xs hidden-sm col-md-3">
<div class="btn-group">
<button type="button" class="btn btn-default light">
<i class="fa fa-refresh"></i>
</button>
<button type="button" class="btn btn-default light">
<i class="fa fa-trash"></i>
</button>
<button type="button" class="btn btn-default light">
<i class="fa fa-plus" onclick="javascript:window.location.href='/department/to_add';"></i>
</button>
</div>
</div>
<div class="col-xs-12 col-md-9 text-right">
<div class="btn-group">
<button type="button" class="btn btn-default light">
<i class="fa fa-chevron-left"></i>
</button>
<button type="button" class="btn btn-default light">
<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>
</div>
</div>
<div class="panel-body pn">
<table id="message-table" class="table admin-form theme-warning tc-checkbox-1">
<thead>
<tr class="">
<th class="text-center hidden-xs">Select</th>
<th class="hidden-xs">部门编号</th>
<th class="hidden-xs">部门名称</th>
<th class="hidden-xs">地址</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="dept">
<tr class="message-unread">
<td class="hidden-xs">
<label class="option block mn">
<input type="checkbox" name="mobileos" value="FR">
<span class="checkbox mn"></span>
</label>
</td>
<td>${dept.sn}</td>
<td>${dept.name}</td>
<td>${dept.address}</td>
<td>
<a href="/department/to_update?sn=${dept.sn}">编辑</a>
<a href="/department/remove?sn=${dept.sn}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<jsp:include page="bottom.jsp"/>
建议同学点击下图标记的两个jsp页面,看一下是哪行代码出现了404问题,
如果是资源文件出现了问题,同学可以参考一下http://class.imooc.com/course/qadetail/92783这个问答,使用basePath来写访问路径,可以避免访问路径资源出现404的问题,祝学习愉快~
我在控制台可以成功输出department的数据,数据库也可以更新数据,但是前端还是显示不出来,我感觉应该是jsp的问题,但是不知道哪里出错了。下面是department_list.jsp的代码。
<%-- Created by IntelliJ IDEA. User: 12640 Date: 2019/2/13 Time: 20:26 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %> <jsp:include page="top.jsp"/> <section id="content" class="table-layout animated fadeIn"> <div class="tray tray-center"> <div class="content-header"> <h2> 部门列表 </h2> <p class="lead"></p> </div> <div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;"> <div class="panel heading-border"> <div class="panel-menu"> <div class="row"> <div class="hidden-xs hidden-sm col-md-3"> <div class="btn-group"> <button type="button" class="btn btn-default light"> <i class="fa fa-refresh"></i> </button> <button type="button" class="btn btn-default light"> <i class="fa fa-trash"></i> </button> <button type="button" class="btn btn-default light"> <i class="fa fa-plus" onclick="javascript:window.location.href='/department/to_add';"></i> </button> </div> </div> <div class="col-xs-12 col-md-9 text-right"> <div class="btn-group"> <button type="button" class="btn btn-default light"> <i class="fa fa-chevron-left"></i> </button> <button type="button" class="btn btn-default light"> <i class="fa fa-chevron-right"></i> </button> </div> </div> </div> </div> <div class="panel-body pn"> <table id="message-table" class="table admin-form theme-warning tc-checkbox-1"> <thead> <tr class=""> <th class="text-center hidden-xs">Select</th> <th class="hidden-xs">部门编号</th> <th class="hidden-xs">部门名称</th> <th class="hidden-xs">地址</th> <th>操作</th> </tr> </thead> <tbody> <c:forEach items="${list}" var="dept"> <tr class="message-unread"> <td class="hidden-xs"> <label class="option block mn"> <input type="checkbox" name="mobileos" value="FR"> <span class="checkbox mn"></span> </label> </td> <td>${currentTime}</td> <td>${dept.name}</td> <td>${dept.address}</td> <td> <a href="/department/to_update?sn=${dept.sn}">编辑</a> <a href="/department/remove?sn=${dept.sn}">删除</a> </td> </tr> </c:forEach> </tbody> </table> </div> </div> </div> </div> </section> <jsp:include page="bottom.jsp"/>
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星