mvc三层架构
Model
●业务处理:业务逻辑(Service)
●数据持久层: CRUD (Dao)
View
●展示数据
●提供链接发起Servlet请求(a, form, im…).
Controller (Servlet)
●接收用户的请求: (req:请求参数、Session信…
●交给业务层处理对应的代码
●控制视图的跳转
lombok插件,一键完成实体类编写
<!-- org.projectlombok/lombok,需要导入插件 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
Maven资源过滤设置:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
8.0链接数据库
连接数据库,单独配置文件版:jdbc:mysql://127.0.0.1:3306/high?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC&useSSL=false
xml文件版:jdbc:mysql://localhost:3306/mybatis?useSSL=true&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8
具体时区:serverTimezone=Asia/Shanghai
方便资源找到web目录下
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
关于页面请求转发与重定向与跳转地址
<%response.sendRedirect("fangKe"); %>
<jsp:forward page="目标网页路径">
//<jsp:param value="" name=""> 可以对跳转到指定页面,并传值
</jsp:forward>
<a href="${pageContext.request.contextpath}/路径"
<jsp:forward page="${pageContext.request.contextPath}/WEB-INF/form.jsp"></jsp:forward>
<!-- 引入 Bootstrap -->
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
aop事务约束
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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
https://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--aop事务支持-->
<!--aop事务支持-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!--配置事务切入-->
<aop:config>
<aop:pointcut id="txPointCut" expression="execution(* com.ssmStart1.dao.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
</aop:config>
javaweb jsp
maven 依赖: