常用配置文件
约 3717 字大约 12 分钟
2025-04-28
数据访问层
db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8
jdbc.user=root
jdbc.password=123456FactoryUtils.java
package com.servlet.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* @author 涂鏊飞tu_aofei@163.com
* @description: 工厂模式工具类 设计模式:简单工厂模式
* @create 2021-10-08 9:49
*/
public class FactoryUtils {
public static <T> T createInstance(String className) {
T instance = null;
try {
Constructor constructor = Class.forName(className).getDeclaredConstructor();
constructor.setAccessible(true);
instance = (T) constructor.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return instance;
}
}JdbcUtils.java
package com.servlet.utils;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Properties;
/**
* @author 涂鏊飞tu_aofei@163.com
* @description: 数据库操作工具类 类描述
* @create 2021-09-01 17:18
*/
public class JdbcUtils {
private static DataSource ds;
static {
try {
//1.加载配置文件
Properties pro = new Properties();
pro.load(JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties"));
//2.获取DataSource
ds = DruidDataSourceFactory.createDataSource(pro);
}
catch (Exception e){
ds = null;
}
}
/*
执行完成后,需要close()关闭连接对象
*/
public static Connection getConnection(){
Connection con;
try {
con = ds.getConnection();
}
catch (Exception ex){
con = null;
}
return con;
}
/* 获取 QueryRunner */
public static QueryRunner getQueryRunner(){
QueryRunner runner = new QueryRunner(ds);
return runner;
}
}PageUtils.java
package com.servlet.utils;
import com.servlet.pojo.Employee;
import com.servlet.service.impl.EmployeeServiceImpl;
import lombok.Data;
import java.util.List;
/**
* @author 涂鏊飞tu_aofei@163.com
* @description: TODO 分页查询工具类
* @create 2021-09-27 16:30
*/
@Data
public class PageUtils {
private EmployeeServiceImpl employeeService;
public PageUtils() {
employeeService = EmployeeServiceImpl.getEmployeeServiceInstance();
}
private Integer size; //每页大小
private Integer index; //当前页码
private Integer pid;
//计算总人数
public Integer getRows() {
Integer rows = 0;
try {
rows = (pid == null || pid.equals("")) ? employeeService.selectAllCount() : employeeService.selectConditionAllCount(pid);
} catch (Exception ex) {
ex.printStackTrace();
}
return rows;
}
//计算总页数
public Integer getPages() {
Integer pages = 0;
Integer rows = getRows();
pages = (rows % size == 0) ? rows / size : rows / size + 1;
return pages;
}
// 判断是否存在pid,来决定查询所有员工或者部门员工
public List<Employee> listCondAll() throws Exception {
List<Employee> employees = null;
if (this.pid == null || (this.pid).equals("")) {
employees = employeeService.selectAllEmployee(this.index, this.size);
} else {
employees = employeeService.selectConditionEmployee(this.pid, this.index, this.size);
}
return employees;
}
}框架
mybatis.xml
<!--mybatis+spring整合之后 -->
<?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">
<configuration>
<!-- 别名-->
<typeAliases>
<package name="com.pojo"/>
</typeAliases>
</configuration><!--整合之前 -->
<?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">
<configuration>
<!-- 引入配置文件-->
<properties resource="properties/db.properties"></properties>
<!-- 别名-->
<typeAliases>
<package name="com.pojo"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
<!-- 配置映射文件-->
<mappers>
<mapper resource="data/HouseingTypeMapper.xml"></mapper>
<!-- 配置java文件和xml文件放在一起,识别 <mapper class="com.mapper.HouseingTypeMapper"></mapper>-->
<mapper resource="data/LandlordMapper.xml"></mapper>
</mappers>
</configuration><?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">
<mapper namespace="com.mapper.HouseingTypeMapper">
<resultMap id="selectAllResultMap" type="HouseingType">
<id column="typeId" property="typeId"/>
<result column="typename" property="typename"/>
</resultMap>
<!-- 无条件查询-->
<select id="selectHouseingType" resultMap="selectAllResultMap">
select * from housingtype
</select>
<select id="groupSelect" resultType="CheckhouseRecordResult">
SELECT sum(cId) 'cid_sum',sum(hId) 'hid_sum' FROM `checkhouserecord`
</select>
<!--单条件查询-->
<!-- <select id="conditionHouseingType" parameterType="java.lang.Integer" resultType="HouseingType">-->
<!-- select * from housingtype where typeId = #{typeId}-->
<!-- </select>-->
<!-- 多条件查询-->
<select id="multipleConditionsHouseingType" resultType="HouseingType">
select * from housingtype where typeId in
<foreach collection="array" item="num" open="(" separator="," close=")">
#{num}
</foreach>
</select>
<!-- 批量删除-->
<delete id="multipleConditionsDelHouseingType" parameterType="CheckRecordVo">
delete from checkhouserecord where cId in
<foreach collection="array" item="n" open="(" separator="," close=")">
#{n}
</foreach>
</delete>
<!--模糊查询-->
<select id="fuzzyselectHouseingType" parameterType="java.lang.String" resultType="HouseingType">
select * from housingtype where typename like "%${value}%"
</select>
<select id="checkRecordVoAsCondition" parameterType="CheckRecordVo" resultType="CheckhouseRecord">
select * from checkhouserecord
<where>
<if test="checkhouseRecord.account != null">
account=#{checkhouseRecord.account}
</if>
<if test="minTime != null || maxTime != null">
and checkDate between #{minTime} and #{maxTime}
</if>
</where>
</select>
<!--插入数据-->
<insert id="insertHouseingType" parameterType="HouseingType">
insert into housingType values (#{typeId},#{typename})
</insert>
<!--删除数据-->
<delete id="delHouseingType" parameterType="java.lang.Integer">
delete from housingType where typeId = #{typeId}
</delete>
<!--修改数据-->
<update id="editHouseingType" parameterType="HouseingType">
update housingType set typename=#{typename} where typeId=#{typeId}
</update>
<resultMap id="landlordhousingResultMap" type="Housing">
<id column="hid" property="hId"/>
<result column="title" property="title"/>
<result column="rent" property="rent"/>
<result column="houseType" property="houseType"/>
<result column="area" property="area"/>
<result column="towardId" property="towardId"/>
<result column="imgList" property="imgList"/>
<result column="facilities" property="facilities"/>
<result column="state" property="state"/>
<result column="aid" property="aid"/>
<result column="address" property="address"/>
<result column="describe" property="describe"/>
<association property="landlord" javaType="com.pojo.Landlord">
<id column="lId" property="lId"></id>
<result column="lName" property="lName"/>
<result column="phone" property="phone"/>
<result column="address" property="address"/>
<result column="idCard" property="idCard"/>
<result column="account" property="account"/>
</association>
</resultMap>
<select id="selectLandlordHousing" resultMap="landlordhousingResultMap">
select *
from landlord l
inner join housing h on l.lId=h.lid
</select>
</mapper>applicationContext.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: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:property-placeholder location="classpath:db.properties" />
<context:component-scan base-package="com" />
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!-- sql映射文件-->
<property name="mapperLocations" value="classpath:data/*.xml"/>
<!-- mybatis配置文件-->
<property name="configLocation" value="classpath:mybatis.xml"/>
</bean>
<!--mybatis扫描器-->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 整合连接池-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 设置扫描范围 mapper代理的实现类-->
<property name="basePackage" value="com.mapper"/>
</bean>
<bean id="studentService" class="com.service.impl.StudentServiceImpl"></bean>
<!--切面类:事务类(启动、提交、回滚)-->
<bean id="shop" class="com.aop.Shop"/>
<aop:aspectj-autoproxy/>
<!-- <aop:config>-->
<!--切点:将事务机制作用于service的所有类的所有方法-->
<!-- <aop:pointcut id="all" expression="execution(* com.service.impl.*.*(..))"/>-->
<!-- <!–切面–>-->
<!-- <aop:aspect ref="shop">-->
<!--通知(增加)-->
<!-- <aop:before method="check" pointcut-ref="all"/> <!–前置通知–>-->
<!-- <aop:after-returning method="ok" pointcut-ref="all"/> <!–后置通知 可以拿到返回值–>-->
<!-- <aop:after method="finallyMethod" pointcut-ref="all"/> <!–后置通知 –>-->
<!-- <aop:after-throwing method="notQualifications" pointcut-ref="all"/> <!–异常通知–>-->
<!-- <aop:around method="aroundActive" pointcut-ref="all"/> <!–环绕通知 –>-->
<!-- </aop:aspect>-->
<!-- </aop:config>-->
</beans>前端
web.xml
<?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">
<!-- <listener>-->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>-->
<!-- </listener>-->
<!-- <context-param>-->
<!-- <param-name>contextConfigLocation</param-name>-->
<!-- <param-value>classpath:applicationContext.xml</param-value>-->
<!-- </context-param>-->
<!-- 首页-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>jsp模板
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
</body>
</html>maven
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>demo_factory</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<spring-version>5.3.6</spring-version>
</properties>
<dependencies>
<!--单元测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<!--Spring整合单元测试-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.6</version>
</dependency>
<!--spring整合mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.4</version>
</dependency>
<!--注解-->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.6</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- 可选模块,按需添加 -->
<!-- AOP -->
<!-- 基于代理的AOP支持 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- 提供与AspectJ的集成 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- JDBC支持包,包括数据源设置和JDBC访问支持 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- 支持单元测试和集成测试Spring组件-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- Spring事务 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- 提供基本的面向Web的集成功能 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- SpringMVC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
</project>spring logback日志配置
<?xml version="1.0" encoding="UTF-8"?>
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
<!-- scan:当此属性设置为true时,配置文档如果发生改变,将会被重新加载,默认值为true -->
<!-- scanPeriod:设置监测配置文档是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。
当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="10 seconds">
<contextName>logback</contextName>
<property resource="application.properties"/>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义后,可以使“${}”来使用变量。 -->
<property name="log.path" value="./logs/${spring.application.name}/${server.port}/"/>
<!--0. 日志格式和颜色渲染 -->
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!--1. 输出到控制台-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为��发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>debug</level>
</filter>
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
<!-- 设置字符集 -->
<charset>UTF-8</charset>
</encoder>
</appender>
<!--2. 输出到文档-->
<!-- 2.1 level为 DEBUG 日志,时间滚动输出 -->
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${log.path}/debug/web_debug.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志归档 -->
<fileNamePattern>${log.path}/debug/web-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文档保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文档只记录debug级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>debug</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 2.2 level为 INFO 日志,时间滚动输出 -->
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档�� -->
<file>${log.path}/info/web_info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 每天日志归档路径以及格式 -->
<fileNamePattern>${log.path}/info/web-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文档保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文档只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 2.3 level为 WARN 日志,时间滚动输出 -->
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${log.path}/warn/web_warn.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/warn/web-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文档保留天数-->
<!-- <maxHistory>15</maxHistory>-->
</rollingPolicy>
<!-- 此日志文档只记录warn级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>warn</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 2.4 level为 ERROR 日志,时间滚动输出 -->
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${log.path}/error/web_error.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/error/web-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文档保留天数-->
<!-- <maxHistory>15</maxHistory>-->
</rollingPolicy>
<!-- 此日志文档只记录ERROR级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、
以及指定<appender>。<logger>仅有一个name属性,
一个可选的level和一个可选的addtivity属性。
name:用来指定受此logger约束的某一个包或者具体的某一个类。
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
如果未设置此属性,那么当前logger将会继承上级的级别。
addtivity:是否向上级logger传递打印信息。默认是true。
<logger name="org.springframework.web" level="info"/>
<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>
-->
<!--
使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:
第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息
第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别:
【logging.level.org.mybatis=debug logging.level.dao=debug】
-->
<!--
root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
不能设置为INHERITED或者同义词NULL。默认是DEBUG
可以包含零个或多个元素,标识这个appender将会添加到这个logger。
-->
<!-- 4. 最终的策略 -->
<!-- 4.1 开发环境:打印控制台-->
<springProfile name="dev">
<logger name="com.sdcm.pmp" level="debug"/>
</springProfile>
<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="DEBUG_FILE"/>
<appender-ref ref="INFO_FILE"/>
<appender-ref ref="WARN_FILE"/>
<appender-ref ref="ERROR_FILE"/>
</root>
<!-- 4.2 生产环境:输出到文档
<springProfile name="pro">
<root level="info">
<appender-ref ref="CONSOLE" />
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="INFO_FILE" />
<appender-ref ref="ERROR_FILE" />
<appender-ref ref="WARN_FILE" />
</root>
</springProfile> -->
</configuration>maven jar打包插件配置
父模块
<properties>
<!-- 指定jdk的版本-->
<java.version>1.8</java.version>
<!-- 是否跳过springboot模块打包插件
true:不会将依赖的jar包打包
false: 将第三方的jar包一起打包
当项目使用web模块打war的时候,此配置项需要设置为true
-->
<spring-boot-maven-plugin.skip>false</spring-boot-maven-plugin.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<!-- 要将源码放上去,需要加入这个插件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 跳过测试 避免发布的时候报错-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
子模块
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--增加jvm参数-->
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<includeSystemScope>true</includeSystemScope>
<skip>${spring-boot-maven-plugin.skip}</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resource</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.parent.basedir}/target</outputDirectory>
<resources>
<resource>
<!-- 文件地址 -->
<directory>${basedir}/target</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<!--打包时过滤的文件-->
<directory>src/main/resources/</directory>
<includes>
<include>security_product/*</include>
<include>security_comp/*</include>
<include>security_dev/*</include>
<include>*</include>
<include>template/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/common/</directory>
</resource>
<resource>
<directory>src/main/resources/${resourcesDir}</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>product</id>
<properties>
<resourcesDir>security_product</resourcesDir>
</properties>
</profile>
<profile>
<id>comp</id>
<properties>
<resourcesDir>security_comp</resourcesDir>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<resourcesDir>security_dev</resourcesDir>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>贡献者
更新日志
2026/4/5 03:39
查看所有更新日志
fb8bc-更新为vuepress于