xsi:schemaLocation=“http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd”
version=“3.1”>
Archetype Created Web Application
contextConfigLocation
classpath:spring-context.xml
org.springframework.web.context.ContextLoaderListener
struts2
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
struts2
*.action
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
true
encoding
UTF-8
encodingFilter
/*
配置pom.xml
第一步就是配置maven-compiler-plugin插件,更改jdk由1.5到1.8
org.apache.maven.plugins
maven-compiler-plugin
3.7.0
1.8
1.8
UTF-8
选择Project Facets,Dynamic Web Module 2.3改为3.1 Java 1.5改为1.8
配置版本号
<hibernate.version>5.2.12.Final</hibernate.version>
<mysql.version>5.1.44</mysql.version>
<spring.version>5.0.1.RELEASE</spring.version>
<struts2.version>2.5.13</struts2.version>
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>2.9.1</log4j.version>
<disruptor.version>3.2.0</disruptor.version>
<junit.version>4.12</junit.version>
<servlet.version>4.0.0</servlet.version>
<jstl.version>1.2</jstl.version>
<standard.version>1.1.2</standard.version>
<tomcat-jsp-api.version>8.0.47</tomcat-jsp-api.version>
配置相关依赖
org.hibernate
hibernate-c3p0
${hibernate.version}
org.hibernate
hibernate-ehcache
${hibernate.version}
mysql
mysql-connector-java
${mysql.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-orm
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-aspects
${spring.version}
org.apache.struts
struts2-core
${struts2.version}
org.apache.struts
struts2-spring-plugin
${struts2.version}
org.slf4j
slf4j-api
${slf4j.version}
org.slf4j
jcl-over-slf4j
${slf4j.version}
runtime
org.apache.logging.log4j
log4j-slf4j-impl
${log4j.version}
org.apache.logging.log4j
log4j-api
${log4j.version}
org.apache.logging.log4j
log4j-core
${log4j.version}
org.apache.logging.log4j
log4j-web
${log4j.version}
runtime
com.lmax
disruptor
${disruptor.version}
junit
junit
${junit.version}
test
javax.servlet
javax.servlet-api
${servlet.version}
provided
jstl
jstl
${jstl.version}
taglibs
standard
${standard.version}
org.apache.tomcat
tomcat-jsp-api
${tomcat-jsp-api.version}
SSH集成
导入echache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=“http://ehcache.org/ehcache.xsd”
updateCheck=“false”>
<defaultCache eternal=“false” maxElementsInMemory=“1000” overflowToDisk=“false” diskPersistent=“false”
timeToIdleSeconds=“0” timeToLiveSeconds=“600” memoryStoreEvictionPolicy=“LRU”/>
<cache name=“com.ltf.one.entity.User” eternal=“false” maxElementsInMemory=“100”
overflowToDisk=“true” diskPersistent=“true” timeToIdleSeconds=“0”
timeToLiveSeconds=“300” memoryStoreEvictionPolicy=“LRU”/>
导入log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
< FATAL < OFF。 monitorInterval : 用于指定log4j自动重新配置的监测间隔时间,单位是s,最小是5s. -->
/root/workspace/lucenedemo/logs
/root/workspace/lucenedemo/logs/error
/root/workspace/lucenedemo/logs/warn
%d{yyyy-MM-dd HH:mm:ss.SSS} [%t-%L] %-5level %logger{36} - %msg%n
<ThresholdFilter level=“trace” onMatch=“ACCEPT”
onMismatch=“DENY” />
<!-- %d{yyyy-MM-dd HH:mm:ss, SSS} : 日志生产时间 %p : 日志输出格式 %c : logger的名称
%m : 日志内容,即 logger.info(“message”) %n : 换行符 %C : Java类名 %L : 日志输出所在行数 %M
: 日志输出所在方法名 hostName : 本地机器名 hostAddress : 本地ip地址 -->
<PatternLayout
pattern=“%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n” />
<RollingFile name=“RollingFileInfo” fileName=“${LOG_HOME}/info.log”
filePattern=“ L O G _ H O M E / {LOG\_HOME}/ LOG_HOME/${date:yyyy-MM}/info-%d{yyyy-MM-dd}-%i.log”>
<ThresholdFilter level=“info” onMatch=“ACCEPT”
onMismatch=“DENY” />
<PatternLayout
pattern=“%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n” />
<TimeBasedTriggeringPolicy interval=“1”
modulate=“true” />
<RollingFile name=“RollingFileWarn” fileName=“${WARN_LOG_FILE_NAME}/warn.log”
filePattern=“ W A R N _ L O G _ F I L E _ N A M E / {WARN\_LOG\_FILE\_NAME}/ WARN_LOG_FILE_NAME/${date:yyyy-MM}/warn-%d{yyyy-MM-dd}-%i.log”>
<ThresholdFilter level=“warn” onMatch=“ACCEPT”
onMismatch=“DENY” />
<PatternLayout
pattern=“%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n” />
<RollingFile name=“RollingFileError” fileName=“${ERROR_LOG_FILE_NAME}/error.log”
filePattern=“ E R R O R _ L O G _ F I L E _ N A M E / {ERROR\_LOG\_FILE\_NAME}/ ERROR_LOG_FILE_NAME/${date:yyyy-MM}/error-%d{yyyy-MM-dd-HH-mm}-%i.log”>
<ThresholdFilter level=“error” onMatch=“ACCEPT”
onMismatch=“DENY” />
<PatternLayout
pattern=“%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n” />
<TimeBasedTriggeringPolicy interval=“1”
modulate=“true” />
spring-context.xml配置
<?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”
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-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!–
吃吃吃 睡睡睡 胖胖胖
-->
吃
睡
胖
.*buy
<bean class=“org.springframework.aop.framework.ProxyFactoryBean”
id=“proxyFactoryBean”>
com.ltf.aop.biz.IBookBiz
myBefore
myFilter
myInterceptor
myException
spring.hbernate.xml(spring和hibernate整合文件)
<?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: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/aop http://www.springframework.org/schema/aop/spring-aop-4.3.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">
<context:property-placeholder location=“classpath:db.properties” />
<!–JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。
所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:
0 -->
<!–获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。
如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
<!–因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod
或automaticTestTable 等方法来提升连接测试的性能。Default: false -->
<bean id=“sessionFactory”
class=“org.springframework.orm.hibernate5.LocalSessionFactoryBean”>
org.hibernate.dialect.MySQLDialect
true
true
com/mwy/book/entity/Book.hbm.xml
<!–
静态代理:
一个代理对象->一个目标对象
BookProxy(BookBizImpl+myMethodBeforeAdvice)->bookBiz
OrderProxy(OrderBizImpl+myMethodBeforeAdvice2)-> OrderBiz
动态代理:
一个代理对象->多个目标对象
–>
<aop:aspectj-autoproxy />
<bean id=“transactionManager”
class=“org.springframework.orm.hibernate5.HibernateTransactionManager”>
<tx:advice id=“txAdvice” transaction-manager=“transactionManager”>
tx:attributes
<tx:method name=“add*” propagation=“REQUIRED” />
<tx:method name=“save*” propagation=“REQUIRED” />
<tx:method name=“insert*” propagation=“REQUIRED” />
<tx:method name=“edit*” propagation=“REQUIRED” />
<tx:method name=“update*” propagation=“REQUIRED” />
<tx:method name=“del*” propagation=“REQUIRED” />
<tx:method name=“remove*” propagation=“REQUIRED” />
<tx:method name=“load*” propagation=“REQUIRED” read-only=“true” />
<tx:method name=“list*” propagation=“REQUIRED” read-only=“true” />
<tx:method name=“select*” propagation=“REQUIRED” read-only=“true” />
<tx:method name=“query*” propagation=“REQUIRED” read-only=“true” />
<tx:method name=“do*” propagation=“REQUIRED” />
</tx:attributes>
</tx:advice>
aop:config
<aop:advisor advice-ref=“txAdvice” pointcut=“execution(* *…*Biz.*(…))” />
</aop:config>
加入db.properties
配置数据库连接池C3P0,数据库连接文件db.properties
db.username=root
db.password=123456
db.driverClass=com.mysql.cj.jdbc.Driver
db.jdbcUrl=jdbc:mysql://127.0.0.1:3306/mybatis_ssm?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=true
#db.username=root
#db.password=123456
#db.driverClass=com.mysql.jdbc.Driver
#db.jdbcUrl=jdbc:mysql://47.100.191.44:3308/lx?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
db.initialPoolSize=10
db.maxPoolSize=20
db.minPoolSize=5
db.maxIdleTime=60
db.acquireIncrement=5
db.maxStatements=0
db.idleConnectionTestPeriod=60
db.acquireRetryAttempts=30
db.breakAfterAcquireFailure=true
db.testConnectionOnCheckout=false
建包(Ctrl+Shift+o 全部导包)
BaseEntity
package com.ltf.base.entity;
import java.io.Serializable;
public class BaseEntity implements Serializable {
private static final long serialVersionUID = -5475556860252527343L;
}
BaseDao
package com.ltf.base.dao;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
public class BaseDao extends HibernateDaoSupport implements Serializable {
private static final long serialVersionUID = 5427369434249665701L;
public void setParam(Query query, Map<String, Object> map) {
if (map == null || map.size() < 1) {
return;
}
Object value = null;
for (Map.Entry<String, Object> entry : map.entrySet()) {
value = entry.getValue();
if (value instanceof Collection) {
query.setParameterList(entry.getKey(), (Collection) value);
} else if (value instanceof Object[]) {
query.setParameterList(entry.getKey(), (Object[]) value);
} else {
query.setParameter(entry.getKey(), value);
}
}
}
public String getCountHql(String hql) {
int index = hql.toUpperCase().indexOf(“FROM”);
return "select count(*) " + hql.substring(index);
}
/**
-
@param hql
-
已经拼装好的
-
@param map
-
@param pageBean
-
@return
*/
public List executeQuery(Session session, String hql, Map<String, Object> map, PageBean pageBean) {
if (pageBean != null && pageBean.isPagination()) {
String countHql = getCountHql(hql);
Query countQuery = session.createQuery(countHql);
this.setParam(countQuery, map);
pageBean.setTotal(countQuery.getSingleResult().toString());
Query query = session.createQuery(hql);
this.setParam(query, map);
query.setFirstResult(pageBean.getStartIndex());
query.setMaxResults(pageBean.getRows());
List list = query.list();
return list;
} else {
Query query = session.createQuery(hql);
this.setParam(query, map);
List list = query.list();
return list;
}
}
}
PageBean
package com.ltf.base.util;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
public class PageBean {
private int page = 1;// 页码
private int rows = 10;// 页大小
private int total = 0;// 总记录数
private boolean pagination = true;// 是否分页
private String url; // 保存上一次请求的URL
private Map<String, String[]> paramMap = new HashMap<>();// 保存上一次请求的参数
/**
-
初始化pagebean的,保存上一次请求的重要参数
-
@param req
*/
public void setRequest(HttpServletRequest req) {
// 1.1 需要保存上一次请求的URL
this.setUrl(req.getRequestURL().toString());
// 1.2 需要保存上一次请求的参数 bname、price
this.setParamMap(req.getParameterMap());
// 1.3 需要保存上一次请求的分页设置 pagination
this.setPagination(req.getParameter(“pagination”));
// 1.4 需要保存上一次请求的展示条目数
this.setRows(req.getParameter(“rows”));
// 1.5 初始化请求的页码 page
this.setPage(req.getParameter(“page”));
}
public void setPage(String page) {
if (StringUtils.isNotBlank(page))
this.setPage(Integer.valueOf(page));
}
public void setRows(String rows) {
if (StringUtils.isNotBlank(rows))
this.setRows(Integer.valueOf(rows));
}
public void setPagination(String pagination) {
// 只有在前台jsp填写了pagination=false,才代表不分页
if (StringUtils.isNotBlank(pagination))
this.setPagination(!“false”.equals(pagination));
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Map<String, String[]> getParamMap() {
return paramMap;
}
public void setParamMap(Map<String, String[]> paramMap) {
this.paramMap = paramMap;
}
public PageBean() {
super();
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getRows() {
return rows;
}
public void setRows(int rows) {
this.rows = rows;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public void setTotal(String total) {
this.total = Integer.parseInt(total);
}
public boolean isPagination() {
return pagination;
}
public void setPagination(boolean pagination) {
this.pagination = pagination;
}
/**
-
获得起始记录的下标
-
@return
*/
public int getStartIndex() {
return (this.page - 1) * this.rows;
}
/**
-
最大页
-
@return
*/
public int maxPage() {
// total % rows == 0 ? total / rows : total / rows +1
return this.total % this.rows == 0 ? this.total / this.rows : this.total / this.rows + 1;
}
/**
-
下一页
-
@return
*/
public int nextPage() {
// 如果当前页小于最大页,那就下一页为当前页+1;如果不小于,说明当前页就是最大页,那就无需+1
return this.page < this.maxPage() ? this.page + 1 : this.page;
}
/**
-
上一页
-
@return
*/
public int previousPage() {
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
![img](https://img-blog.csdnimg.cn/img_convert/1cb2d299c616042e2c05de4280f21dd6.jpeg)
最后
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
this.total = Integer.parseInt(total);
}
public boolean isPagination() {
return pagination;
}
public void setPagination(boolean pagination) {
this.pagination = pagination;
}
/**
-
获得起始记录的下标
-
@return
*/
public int getStartIndex() {
return (this.page - 1) * this.rows;
}
/**
-
最大页
-
@return
*/
public int maxPage() {
// total % rows == 0 ? total / rows : total / rows +1
return this.total % this.rows == 0 ? this.total / this.rows : this.total / this.rows + 1;
}
/**
-
下一页
-
@return
*/
public int nextPage() {
// 如果当前页小于最大页,那就下一页为当前页+1;如果不小于,说明当前页就是最大页,那就无需+1
return this.page < this.maxPage() ? this.page + 1 : this.page;
}
/**
-
上一页
-
@return
*/
public int previousPage() {
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。[外链图片转存中…(img-SIMgVqC7-1713372523723)]
[外链图片转存中…(img-DPnpxiI3-1713372523724)]
[外链图片转存中…(img-uOC5ShpZ-1713372523724)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
![img](https://img-blog.csdnimg.cn/img_convert/1cb2d299c616042e2c05de4280f21dd6.jpeg)
最后
[外链图片转存中…(img-TrCnPXj2-1713372523724)]
[外链图片转存中…(img-kA0Zi8H4-1713372523724)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!