部门管理模块启动报错
访问http://localhost:8080/department/list,启动的时候报错,后台没有错误信息,能够正常连接到服务器,页面报服务器内部错误
package com.imooc.oa.entity;
public class Department {
private String sn;
private String name;
private String address;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.4//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.imooc.oa.dao.DepartmentDao">
<resultMap id="department" type="Department">
<id property="sn" column="sn" javaType="String"/>
<result property="name" column="name" javaType="String"/>
<result property="address" column="address" javaType="String"/>
</resultMap>
<insert id="insert" parameterType="Department">
insert into department
values (#{sn}, #{name}, #{address})
</insert>
<update id="update" parameterType="Department">
<!--name=#{name},第一个name是数据库的字段名,第二个name是实体类的属性名-->
update department set name=#{name},address=#{address} where sn=#{sn}
</update>
<delete id="delete" parameterType="String">
delete
from department
where sn = #{sn}
</delete>
<select id="select" parameterType="String" resultMap="department">
select *
from department
where sn = #{sn}
</select>
<select id="selectAll" resultMap="department">
select *
from department
</select>
</mapper>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 开启自动扫描-->
<context:component-scan base-package="com.imooc.oa.dao"/>
<!-- 配置数据源-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost:3306/oa?serverTimezone=Hongkong&useUnicode=true&characterEncoding=utf-8&userSSL=false"/>
<property name="username" value="root"/>
<property name="password" value="1111"/>
</bean>
<!-- 配置session工厂-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.imooc.oa.entity"/>
</bean>
<!-- 配置映射器接口-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sessionFactory"/>
<property name="basePackage" value="com.imooc.oa.dao"/>
</bean>
</beans>
package com.imooc.oa.biz;
import com.imooc.oa.entity.Department;
import java.util.List;
public interface DepartmentBiz {
void add(Department department);
void edit(Department department);
void remove(String sn);
Department get(String sn);
List<Department> getAll();
}
package com.imooc.oa.biz.impl;
import com.imooc.oa.biz.DepartmentBiz;
import com.imooc.oa.dao.DepartmentDao;
import com.imooc.oa.entity.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("departmentBiz")
public class DepartmentBizImpl implements DepartmentBiz {
@Qualifier("departmentDao")
@Autowired
private DepartmentDao departmentDao;
@Override
public void add(Department department) {
departmentDao.insert(department);
}
@Override
public void edit(Department department) {
departmentDao.update(department);
}
@Override
public void remove(String sn) {
departmentDao.delete(sn);
}
@Override
public Department get(String sn) {
return departmentDao.select(sn);
}
@Override
public List<Department> getAll() {
return departmentDao.selectAll();
}
}
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<import resource="spring-dao.xml"/>
<!-- 自动扫描-->
<context:component-scan base-package="com.imooc.oa.biz"/>
<!-- aspect自动代理打开-->
<aop:aspectj-autoproxy/>
<!-- 声明事务管理器-->
<bean id="transationManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 声明通知-->
<tx:advice id="txAdvice" transaction-manager="transationManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="search*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 通知与切入点关联-->
<aop:config>
<!-- 声明切入点-->
<aop:pointcut id="txpc" expression="execution(* com.imooc.oa.biz.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txpc"/>
</aop:config>
</beans>
package com.imooc.oa.controller;
import com.imooc.oa.biz.DepartmentBiz;
import com.imooc.oa.entity.Department;
import com.imooc.oa.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@Controller("departmentController")
@RequestMapping("/department")
public class DepartmentController {
@Autowired
private DepartmentBiz departmentBiz;
@RequestMapping("/list")
public String list(Map<String,Object> map){
map.put("list",departmentBiz.getAll());
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){
departmentBiz.remove(sn);
return "redirect:list";
}
}
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<import resource="spring-biz.xml"/>
<!--开启自动扫描-->
<context:component-scan base-package="com.imooc.oa.controller"/>
<!-- 开启mvc注解-->
<mvc:annotation-driven/>
<!-- 将静态资源交给servlet处理-->
<mvc:default-servlet-handler/>
<!-- springMVC视图转换器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 配置访问路径前缀-->
<property name="prefix" value="/WEB-INF/pages/"/>
<!-- 配置访问路径后缀-->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<import resource="spring-biz.xml"/>
<!--开启自动扫描-->
<context:component-scan base-package="com.imooc.oa.controller"/>
<!-- 开启mvc注解-->
<mvc:annotation-driven/>
<!-- 将静态资源交给servlet处理-->
<mvc:default-servlet-handler/>
<!-- springMVC视图转换器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 配置访问路径前缀-->
<property name="prefix" value="/WEB-INF/pages/"/>
<!-- 配置访问路径后缀-->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="top.jsp"/>
<section id="content_wrapper">
<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.id}">编辑</a>
<a href="/department/remove?sn=${dept.id}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<jsp:include page="bottom.jsp"/>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<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">
<form:form action="/department/add" modelAttribute="department" id="admin-form" name="addForm">
<div class="panel-body bg-light">
<div class="section-divider mt20 mb40">
<span> 基本信息 </span>
</div>
<div class="section row">
<div class="col-md-6">
<label for="sn" class="field prepend-icon">
<form:input path="sn" cssClass="gui-input" placeholder="编号..."/>
<label for="sn" class="field-icon">
<i class="fa fa-user"></i>
</label>
</label>
</div>
<div class="col-md-6">
<label for="name" class="field prepend-icon">
<form:input path="name" cssClass="gui-input" placeholder="名称..." />
<label for="name" class="field-icon">
<i class="fa fa-user"></i>
</label>
</label>
</div>
</div>
<div class="section">
<label for="address" class="field prepend-icon">
<form:input path="address" cssClass="gui-input" placeholder="地址..." />
<label for="address" class="field-icon">
<i class="fa fa-lock"></i>
</label>
</label>
</div>
<div class="panel-footer text-right">
<button type="submit" class="button"> 保存 </button>
<button type="button" class="button" onclick="javascript:window.history.go(-1);"> 返回 </button>
</div>
</div>
</form:form>
</div>
</div>
</div>
</section>
<jsp:include page="bottom.jsp"/>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<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">
<form:form action="/department/update" modelAttribute="department" id="admin-form" name="addForm">
<div class="panel-body bg-light">
<div class="section-divider mt20 mb40">
<span> 基本信息 </span>
</div>
<div class="section row">
<div class="col-md-6">
<label for="sn" class="field prepend-icon">
<form:input path="sn" cssClass="gui-input" placeholder="编号..." readonly="true"/>
<label for="sn" class="field-icon">
<i class="fa fa-user"></i>
</label>
</label>
</div>
<div class="col-md-6">
<label for="name" class="field prepend-icon">
<form:input path="name" cssClass="gui-input" placeholder="名称..." />
<label for="name" class="field-icon">
<i class="fa fa-user"></i>
</label>
</label>
</div>
</div>
<div class="section">
<label for="address" class="field prepend-icon">
<form:input path="address" cssClass="gui-input" placeholder="地址..." />
<label for="address" class="field-icon">
<i class="fa fa-lock"></i>
</label>
</label>
</div>
<div class="panel-footer text-right">
<button type="submit" class="button"> 保存 </button>
<button type="button" class="button" onclick="javascript:window.history.go(-1);"> 返回 </button>
</div>
</div>
</form:form>
</div>
</div>
</div>
</section>
<jsp:include page="bottom.jsp"/>
31
收起
正在回答 回答被采纳积分+1
2回答
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星