完整的Spring-boot实现(部门与员⼯)完整的spring-boot实现
⼯具:jdk1.7  -- eclipse --  Maven
⽬的:实现通过部门ID查询部门及所有员⼯信息
⽬录结构:
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<input type="button" value="查询员⼯信息" οnclick="window.location.href='/spring-mvc-jpa/getAllEmp'"><br/>
<input type="button" value="模糊查询员⼯" οnclick="window.location.href='/spring-mvc-jpa/jsp/LikeEmp.jsp'"><br/>
<input type="button" value="查询部门信息" οnclick="window.location.href='/spring-mvc-jpa/getAllDept'"><br/>
<input type="button" value="部门与员⼯信息" οnclick="window.location.href='/spring-mvc-jpa/jsp/DeptNo.jsp'"><br/>
<input type="button" value="添加部门信息" οnclick="window.location.href='/spring-mvc-jpa/jsp/AddDept.jsp'"><br/>
</body>
</html>
DeptNo.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>springboot aop
<body>
<form action="/spring-mvc-jpa/getAllMessage" method="get">
<table>
<tr>
<td>部门号:<input type="text" name="did" id="did"></td>
</tr>
</table>
<input type="submit" value="查询">
</form>
</body>
</html>
DeptAndEmp.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="java.sun/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<table border="1px" cellpadding="0px" cellspacing="0px">
<tr>
<td>编号</td>
<td>姓名</td>
<td>雇佣⽇期</td>
<td>薪⽔</td>
<td>所属部门</td>
<td>部门地址</td>
</tr>
<c:forEach var="h" items="${allList.sets}">
<tr>
<td>${h.eid}</td>
<td>${h.ename}</td>
<td>${h.hiredate}</td>
<td>${h.salery}</td>
<td>${allList.dname}</td>
<td>${allList.addres}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
配置环境⽂件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="/2001/XMLSchema-instance"
xmlns="java.sun/xml/ns/javaee"
xsi:schemaLocation="java.sun/xml/ns/javaee
java.sun/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/l</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.t.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>l</param-value>
</context-param>
<!--过滤器,防⽌乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>jpa.support.OpenEntityManagerInViewFilter</filter-class>
<init-param>
<!-- 指定jpa.LocalEntityManagerFactoryBean在spring配置⽂件中的名称,默认值为entityManagerFactory
如果LocalEntityManagerFactoryBean在spring中的名称不是entityManagerFactory,该参数⼀定要指定,否则会出现不到entityManagerFactory的例外 -->  <param-name>entityManagerFactoryBeanName</param-name>
<param-value>entityManagerFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance" xmlns:p="/schema/p"
xmlns:context="/schema/context"
xmlns:mvc="/schema/mvc"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-3.0.xsd
/schema/context
/schema/context/spring-context-3.0.xsd
/schema/mvc
/schema/mvc/spring-mvc-3.0.xsd">
<!--注解驱动配置-->
<mvc:annotation-driven />
<!--⾃动扫描⽬录下所有的类⽂件 -->
<context:component-scan base-package="ller" />
<!--对模型视图名称的解析 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:aop="/schema/aop"
xmlns:tx="/schema/tx"
xmlns:context="/schema/context"
xmlns:p="/schema/p"
xmlns:cache="/schema/cache"
xmlns:jaxws="/jaxws"
xmlns:jpa="/schema/data/jpa"
xsi:schemaLocation="
/schema/beans
/schema/beans/spring-beans-3.1.xsd
/schema/tx
/schema/tx/spring-tx-3.1.xsd
/schema/aop
/schema/aop/spring-aop-3.1.xsd
/schema/context
/schema/context/spring-context-3.1.xsd
/schema/cache
/schema/cache/spring-cache-3.1.xsd
/jaxws /schemas/jaxws.xsd
/schema/data/jpa /schema/data/jpa/spring-jpa.xsd"                    default-lazy-init="true">
<!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置⽂件扫描 -->
<context:component-scan base-package="com.java">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 属性⽂件位置 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 数据源 -->

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。