代宇航用户管理并推送

王健旭材料管理
喻廷屿材料出入库管理
孙佳兴预约管理并测试
赵文博实验室管理
main
your-name 2 weeks ago
parent 5c3ce991b8
commit b22752797d

@ -0,0 +1,19 @@
<component name="libraryTable">
<library name="aspectjweaver-1.9.7 (2)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/aspectjweaver-1.9.7.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/commons-logging-1.1.1.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/servlet-api.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-aop-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-aspects-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-beans-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-context-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-core-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-expression-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-web-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-webmvc-5.1.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,16 @@
<component name="libraryTable">
<library name="aspectjweaver-1.9.7 (3)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/aspectjweaver-1.9.7.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/commons-logging-1.1.1.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-aop-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-beans-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-context-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-core-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-expression-5.1.6.RELEASE.jar!/" />
<root url="jar://$PROJECT_DIR$/equipment-SpringMVCProject/web/WEB-INF/lib/spring-web-5.1.6.RELEASE.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<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: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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 1. 扫描Controller包 -->
<context:component-scan base-package="com.ssm.controller"/>
<!-- 2. 开启注解驱动(解决请求映射、参数绑定) -->
<mvc:annotation-driven/>
<!-- 3. 放行静态资源jsp、html、css等 -->
<mvc:default-servlet-handler/>
<!-- 4. 视图解析器对应WEB-INF/view下的jsp文件 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

@ -0,0 +1,16 @@
<%--
Created by IntelliJ IDEA.
User: AA7
Date: 2026/5/13
Time: 14:12
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>入门程序</title>
</head>
<body>
success!
</body>
</html>

@ -0,0 +1,16 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>操作成功</title>
</head>
<body>
<h2>Success!</h2>
<p>实验室编号:${lab.labId}</p>
<p>实验室名称:${lab.labName}</p>
<p>位置:${lab.location}</p>
<p>容纳人数:${lab.capacity}</p>
<p>状态:${lab.status}</p>
<p>管理员:${lab.manager}</p>
</body>
</html>

@ -0,0 +1,17 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>操作成功</title>
</head>
<body>
<h2>Success!</h2>
<p>材料编号:${material.mid}</p>
<p>材料名称:${material.mname}</p>
<p>规格型号:${material.spec}</p>
<p>库存数量:${material.stockNum}</p>
<p>单位:${material.unit}</p>
<p>单价:${material.price}</p>
<p>供应商:${material.supplier}</p>
</body>
</html>

@ -0,0 +1,16 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>操作成功</title>
</head>
<body>
<h2>Success!</h2>
<p>记录编号:${stock.stockId}</p>
<p>材料编号:${stock.mid}</p>
<p>操作类型:${stock.type}</p>
<p>数量:${stock.num}</p>
<p>操作日期:${stock.opDate}</p>
<p>操作人:${stock.operator}</p>
</body>
</html>

@ -0,0 +1,16 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>操作成功</title>
</head>
<body>
<h2>Success!</h2>
<p>预约编号:${reservation.rid}</p>
<p>用户编号:${reservation.uid}</p>
<p>实验室编号:${reservation.labId}</p>
<p>开始日期:${reservation.startDate}</p>
<p>结束日期:${reservation.endDate}</p>
<p>状态:${reservation.status}</p>
</body>
</html>

@ -0,0 +1,15 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>操作成功</title>
</head>
<body>
<h2>Success!</h2>
<p>用户编号:${user.uid}</p>
<p>用户名:${user.username}</p>
<p>真实姓名:${user.realName}</p>
<p>手机号:${user.phone}</p>
<p>角色:${user.role}</p>
</body>
</html>

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- 1. 编码过滤器解决POST请求和页面乱码 -->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 2. SpringMVC核心控制器直接从WEB-INF加载springmvc.xml -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 3. 欢迎页(可选,不会报错) -->
<welcome-file-list>
<welcome-file>addUser.jsp</welcome-file>
</welcome-file-list>
</web-app>

@ -0,0 +1,25 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>实验室管理</title>
</head>
<body>
<h3>添加实验室信息</h3>
<form action="${pageContext.request.contextPath}/lab/newadd" method="post">
实验室编号:<input type="text" name="labId"><br><br>
实验室名称:<input type="text" name="labName"><br><br>
位置:<input type="text" name="location"><br><br>
容纳人数:<input type="text" name="capacity"><br><br>
状态:
<select name="status">
<option value="可用">可用</option>
<option value="维修中">维修中</option>
<option value="停用">停用</option>
</select><br><br>
管理员:<input type="text" name="manager"><br><br>
<input type="submit" value="添加">
<input type="reset" value="重置">
</form>
</body>
</html>

@ -0,0 +1,21 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>添加材料</title>
</head>
<body>
<h3>添加材料信息</h3>
<form action="${pageContext.request.contextPath}/material/newadd" method="post">
材料编号:<input type="text" name="mid"><br><br>
材料名称:<input type="text" name="mname"><br><br>
规格型号:<input type="text" name="spec"><br><br>
库存数量:<input type="text" name="stockNum"><br><br>
单位:<input type="text" name="unit"><br><br>
单价:<input type="text" name="price"><br><br>
供应商:<input type="text" name="supplier"><br><br>
<input type="submit" value="添加">
<input type="reset" value="重置">
</form>
</body>
</html>

@ -0,0 +1,24 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>材料出入库</title>
</head>
<body>
<h3>添加材料出入库记录</h3>
<form action="${pageContext.request.contextPath}/stock/newadd" method="post">
记录编号:<input type="text" name="stockId"><br><br>
材料编号:<input type="text" name="mid"><br><br>
操作类型:
<select name="type">
<option value="入库">入库</option>
<option value="出库">出库</option>
</select><br><br>
数量:<input type="text" name="num"><br><br>
操作日期:<input type="date" name="opDate"><br><br>
操作人:<input type="text" name="operator"><br><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>

@ -0,0 +1,25 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>预约管理</title>
</head>
<body>
<h3>添加预约信息</h3>
<form action="${pageContext.request.contextPath}/reservation/newadd" method="post">
预约编号:<input type="text" name="rid"><br><br>
用户编号:<input type="text" name="uid"><br><br>
实验室编号:<input type="text" name="labId"><br><br>
开始日期:<input type="date" name="startDate"><br><br>
结束日期:<input type="date" name="endDate"><br><br>
状态:
<select name="status">
<option value="待审核">待审核</option>
<option value="已通过">已通过</option>
<option value="已拒绝">已拒绝</option>
</select><br><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>

@ -0,0 +1,24 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<meta charset="UTF-8">
<title>添加用户</title>
</head>
<body>
<h3>添加用户信息</h3>
<form action="${pageContext.request.contextPath}/user/newadd" method="post">
用户编号:<input type="text" name="uid"><br><br>
用户名:<input type="text" name="username"><br><br>
密码:<input type="password" name="password"><br><br>
真实姓名:<input type="text" name="realName"><br><br>
手机号:<input type="text" name="phone"><br><br>
角色:
<select name="role">
<option value="管理员">管理员</option>
<option value="普通用户">普通用户</option>
</select><br><br>
<input type="submit" value="添加">
<input type="reset" value="重置">
</form>
</body>
</html>

@ -0,0 +1,16 @@
<%--
Created by IntelliJ IDEA.
User: AA7
Date: 2026/4/23
Time: 9:07
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>入门程序</title>
</head>
<body>
<a href="hello">hello world</a>
</body>
</html>

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 1. 配置所有实体类Bean -->
<bean id="user" class="com.ssm.aop.xml.User">
<property name="username" value="daiyuhang"/>
<property name="userpass" value="123456"/>
<property name="truename" value="代宇航"/>
<property name="age" value="20"/>
<property name="role" value="管理员"/>
</bean>
<bean id="material" class="com.ssm.aop.xml.Material">
<property name="materialId" value="M001"/>
<property name="materialName" value="试管"/>
<property name="type" value="玻璃耗材"/>
<property name="stock" value="100"/>
<property name="unit" value="个"/>
</bean>
<bean id="nowDate" class="java.util.Date"/>
<bean id="startDate" class="java.util.Date"/>
<bean id="endDate" class="java.util.Date"/>
<bean id="materialRecord" class="com.ssm.aop.xml.MaterialRecord">
<property name="recordId" value="R001"/>
<property name="materialId" value="M001"/>
<property name="operator" value="喻廷屿"/>
<property name="nums" value="20"/>
<property name="operateDate" ref="nowDate"/>
<property name="type" value="入库"/>
</bean>
<bean id="appointment" class="com.ssm.aop.xml.Appointment">
<property name="appointmentId" value="A001"/>
<property name="username" value="孙佳兴"/>
<property name="labId" value="L001"/>
<property name="startTime" ref="startDate"/>
<property name="endTime" ref="endDate"/>
<property name="purpose" value="化学实验"/>
</bean>
<bean id="laboratory" class="com.ssm.aop.xml.Laboratory">
<property name="labId" value="L001"/>
<property name="labName" value="化学实验室1号"/>
<property name="location" value="实验楼3楼"/>
<property name="capacity" value="30"/>
<property name="status" value="空闲"/>
</bean>
<!-- 2. 配置日志通知类Bean -->
<bean id="log" class="com.ssm.aop.xml.Log"/>
<!-- 3. AOP配置切面、切入点、前置通知 -->
<aop:config>
<!-- 定义切面,切面=通知类+切入点 -->
<aop:aspect ref="log">
<!-- 定义切入点匹配com.ssm.aop.xml包下所有类的printInfo()方法 -->
<aop:pointcut id="printInfoPointcut" expression="execution(* com.ssm.aop.xml.*.printInfo(..))"/>
<!-- 前置通知在切入点方法执行前调用beforeLog方法 -->
<aop:before method="beforeLog" pointcut-ref="printInfoPointcut"/>
</aop:aspect>
</aop:config>
</beans>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
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">
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.ssm.di.annotation"/>
</beans>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!-- mybatis全局配置文件 -->
<configuration>
</configuration>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<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: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/tool http://www.springframework.org/schema/tool/spring-tool.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
</beans>

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 1. 配置所有实体类Bean -->
<bean id="user" class="com.ssm.aop.xml.User">
<property name="username" value="daiyuhang"/>
<property name="userpass" value="123456"/>
<property name="truename" value="代宇航"/>
<property name="age" value="20"/>
<property name="role" value="管理员"/>
</bean>
<bean id="material" class="com.ssm.aop.xml.Material">
<property name="materialId" value="M001"/>
<property name="materialName" value="试管"/>
<property name="type" value="玻璃耗材"/>
<property name="stock" value="100"/>
<property name="unit" value="个"/>
</bean>
<bean id="nowDate" class="java.util.Date"/>
<bean id="startDate" class="java.util.Date"/>
<bean id="endDate" class="java.util.Date"/>
<bean id="materialRecord" class="com.ssm.aop.xml.MaterialRecord">
<property name="recordId" value="R001"/>
<property name="materialId" value="M001"/>
<property name="operator" value="喻廷屿"/>
<property name="nums" value="20"/>
<property name="operateDate" ref="nowDate"/>
<property name="type" value="入库"/>
</bean>
<bean id="appointment" class="com.ssm.aop.xml.Appointment">
<property name="appointmentId" value="A001"/>
<property name="username" value="孙佳兴"/>
<property name="labId" value="L001"/>
<property name="startTime" ref="startDate"/>
<property name="endTime" ref="endDate"/>
<property name="purpose" value="化学实验"/>
</bean>
<bean id="laboratory" class="com.ssm.aop.xml.Laboratory">
<property name="labId" value="L001"/>
<property name="labName" value="化学实验室1号"/>
<property name="location" value="实验楼3楼"/>
<property name="capacity" value="30"/>
<property name="status" value="空闲"/>
</bean>
<!-- 2. 配置日志通知类Bean -->
<bean id="log" class="com.ssm.aop.xml.Log"/>
<!-- 3. AOP配置切面、切入点、前置通知 -->
<aop:config>
<!-- 定义切面,切面=通知类+切入点 -->
<aop:aspect ref="log">
<!-- 定义切入点匹配com.ssm.aop.xml包下所有类的printInfo()方法 -->
<aop:pointcut id="printInfoPointcut" expression="execution(* com.ssm.aop.xml.*.printInfo(..))"/>
<!-- 前置通知在切入点方法执行前调用beforeLog方法 -->
<aop:before method="beforeLog" pointcut-ref="printInfoPointcut"/>
</aop:aspect>
</aop:config>
</beans>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"
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">
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.ssm.di.annotation"/>
</beans>

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<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:tx="http://www.springframework.org/schema/tx"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
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-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- 1.自动扫描包希望Spring管理所有业务逻辑组件、Bean等,SpringMVC负责网站跳转逻辑的控制Controller
注意①当springmvc.xml配置了只扫描@Controller此处就要配
除了标了@Controller注解的控制器以外都扫描即配置子标签
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> -->
<context:component-scan base-package="com.ssm">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 2.引入db.properties
注意:①方式二:<bean id="" class="PropertyPlaceholderConfigurer"> -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 3.引入数据库的数据源配置:
注意①还可以配置事务控制、AOP等
②当使用c3p0连接池时配置如下
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean> -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<!-- 这里报错说明类中不存在这个属性,需要改成规定的属性名 -->
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean>
<!-- 事务管理器DataSourceTransactionManager该类在spring-jdbc包中指定这个事务管理器管理配置的dataSource数据源 -->
<!-- <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean> -->
<!-- 开启基于注解的事务 -->
<!-- <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/> -->
<!-- 4.整合mybatis配置:创建MyBatis核心对象SqlSessionFactory整合关键步骤
目的:(1)想让Spring管理所有组件包括mapper
以后Service层要调用Dao层时只需使用@Autowired注解自动注入即可。
这样就避免了每次操作增删改查之前需要先获取到SqlSessionFactory->SqlSession->getMapper方法获得动态代理对象
即接口类的对象,然后才能操作具体增删改查操作。
(2)Spring声明式事务非常强大想让Spring管理事务。
注意①SqlSessionFactoryBean类能创建出SqlSessionFactory对象意味着容器一启动让容器帮我们创建SqlSessionFactory-->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 访问数据库必然需要数据源,管理数据库的连接,提高数据库性能,在数据源中配置使用的连接池 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 加载MyBatis全局配置文件config.xml如果config.xml中没有东西可以删掉
但一般建议留下可以放一些不太常用的配置如全局参数settings、数据库提供厂商等配置 -->
<!-- <property name="configLocation" value="classpath:config.xml"></property> -->
<!-- 指定SQL映射文件的位置当SQL映射文件和接口名不一致时使用该方法指定。
(不讲)?如果名字一致,则可以使用<mybatis:scan base-package=""/>扫描所有mapper SQL映射文件(报错mybatis前缀未绑定)? -->
<property name="mapperLocations" value="classpath:com/ssm/mapper/*.xml"></property>
<!-- 此处还可以配置别名处理器等,这些以前都是在全局配置文件中定义的现在都变成sqlSessionFactoryBean的一个属性,
相当于mybatis全局配置文件中的内容都拿到Spring配置文件来配置。 -->
</bean>
<!-- 5.扫描所有的mapper接口类让这些mapper能够自动注入
base-package:指定mapper接口的包名
注意:① 查找类路径下的映射器并自动将它们创建成MapperFactoryBean
即扫描所有的mapper接口类让这些mapper能够自动注入
② 如果有红叉报错也可以用,是约束引入有问题,不影响;
③ 以前还有这种写法(老版的项目一般这么做):
a.使用MapperScannerConfigurer
<bean class="MapperScannerConfigurer">
<property name="basePackage" value="Dao接口包名"/>
<bean> 或者
b.采用实体DAO调用方式采用接口org.apache.ibatis.session.SqlSession的实现类org.mybatis.spring.SqlSessionTemplate
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
-->
<mybatis-spring:scan base-package="com.ssm.mapper"/>
</beans>

@ -0,0 +1,63 @@
<?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">
<!-- 映射文件存放CRUD的sql语句 -->
<mapper namespace="com.ssm.mapper.DemoMapper">
<select id="getDemoById" resultMap="DemoResult" parameterType="Integer">
SELECT did,dname,comment
FROM Demo d
WHERE d.did=#{did}
</select>
<resultMap type="com.ssm.entity.Demo" id="DemoResult">
<id property="did" column="did"/>
<result property="dname" column="dname"/>
<result property="comment" column="comment"/>
</resultMap>
<select id="getDemoAll" resultMap="DemoResult" parameterType="int">
SELECT did,dname,comment
FROM Demo d
WHERE 1=1
limit #{param1},#{param2}
</select>
<insert id="addDemo" parameterType="com.ssm.entity.Demo">
insert into Demo(dname,comment)
values(#{dname},#{comment})
</insert>
<update id="updateDemo" parameterType="com.ssm.entity.Demo">
update Demo set dname=#{dname},comment=#{comment} where did=#{did}
</update>
<delete id="deleteDemoById" parameterType="Integer">
<!-- delete from 表名 where 列名称=某值 -->
delete from Demo where did=#{did}
</delete>
<delete id="deleteDemoAll">
<!-- delete from 表名 -->
delete from Demo
</delete>
<select id="countTotlePage" resultType="Integer">
SELECT count(*)
FROM Demo d
</select>
<select id="findDemoByDid" resultMap="DemoResult" parameterType="Integer">
SELECT did,dname,comment
FROM Demo d
WHERE d.did=#{did}
</select>
<!-- 模糊查询 -->
<select id="searchDemoByCondition" parameterType="String"
resultMap="DemoResult">
SELECT did,dname,comment
FROM Demo d
WHERE d.dname like '%${value}%' or d.comment like '%${value}%'
</select>
</mapper>

@ -0,0 +1,4 @@
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/ssm_farm?serverTimezone=Asia/Shanghai
user=root
password=root

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!-- 配置扫描器
只扫描标了@Controller的控制器
use-default-filters="false"禁用掉默认的过滤行为,只包含才会生效。即:
<context:component-scan base-package="com.ssm" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> -->
<!-- <context:component-scan base-package="com.ssm"></context:component-scan> -->
<context:component-scan base-package="com.ssm" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property> <!-- 前缀 -->
<property name="suffix" value=".jsp"></property> <!-- 后缀 -->
</bean>
<!-- 处理动态资源是SpringMVC的基础配置可以协调很多功能一般写SpringMVC项目都加上 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 正确的处理静态资源 -->
<mvc:default-servlet-handler/>
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>
</beans>
Loading…
Cancel
Save