yonge 6 년 전
부모
커밋
766c3f68b8

+ 71 - 0
src/main/java/com/ym/mec/collectfee/common/dao/BaseDAO.java

@@ -0,0 +1,71 @@
+/**
+ * GenericDAO.java 
+ * Copyright © 2015-2015
+ * 
+ * @author pengdc
+ * @create 2015年7月13日
+ */
+package com.ym.mec.collectfee.common.dao;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * DAO操作基类
+ */
+public interface BaseDAO<PK extends Serializable, T>{
+
+	/**
+	 * 通过主键id获取对象
+	 * @author pengdc
+	 * @param id
+	 * @return T
+	 */
+	public T get(final PK id);
+
+	/**
+	 * 更新实体对象
+	 * @author pengdc
+	 * @param bean
+	 * @return int
+	 */
+	public int update(T bean);
+
+	/**
+	 * 通过主键id删除对象
+	 * @author pengdc
+	 * @param id
+	 * @return int
+	 */
+	public int delete(final PK id);
+	
+	/**
+	 * 写入实体对象
+	 * @author pengdc
+	 * @param bean
+	 * @return int
+	 */
+	public long insert(T bean);
+	/**
+	 * 通过参数查找所有结果集
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public List<T> findAll(Map<String, Object> params);
+	/**
+	 * 通过参数查找结果集,适合分页场景
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public List<T> queryPage(Map<String, Object> params);
+	/**
+	 * 通过参数查找结果集数目
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public int findCount(Map<String, Object> params);
+}

+ 14 - 0
src/main/java/com/ym/mec/collectfee/common/dao/BaseIntEnum.java

@@ -0,0 +1,14 @@
+package com.ym.mec.collectfee.common.dao;
+
+/**
+ * 枚举类基础类
+ */
+public interface BaseIntEnum<E extends Enum<E>> {
+
+	/**
+	 * 获取枚举类的code值
+	 * @return
+	 */
+	public int getCode();
+
+}

+ 14 - 0
src/main/java/com/ym/mec/collectfee/common/dao/BaseStringEnum.java

@@ -0,0 +1,14 @@
+package com.ym.mec.collectfee.common.dao;
+
+/**
+ * 枚举类基础类
+ */
+public interface BaseStringEnum<E extends Enum<E>> {
+
+	/**
+	 * 获取枚举类的code值
+	 * @return
+	 */
+	public String getName();
+
+}

+ 58 - 0
src/main/java/com/ym/mec/collectfee/common/dao/IntEnumTypeHandler.java

@@ -0,0 +1,58 @@
+package com.ym.mec.collectfee.common.dao;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+
+/**
+ * 枚举类转换器
+ * @author pengdc
+ */
+@SuppressWarnings("rawtypes")
+public class IntEnumTypeHandler extends BaseTypeHandler<BaseIntEnum> {
+
+	private Class<BaseIntEnum> type;
+
+	public IntEnumTypeHandler(Class<BaseIntEnum> type) {
+		if (type == null)
+			throw new IllegalArgumentException("Type argument cannot be null");
+		this.type = type;
+	}
+
+	@Override
+	public void setNonNullParameter(PreparedStatement ps, int i, BaseIntEnum parameter, JdbcType jdbcType) throws SQLException {
+		if (jdbcType == null) {
+			ps.setString(i, String.valueOf(parameter.getCode()));
+		} else {
+			ps.setObject(i, parameter.getCode(), jdbcType.TYPE_CODE); // see r3589
+		}
+	}
+
+	@Override
+	public BaseIntEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
+		return convert(rs.getInt(columnName));
+	}
+
+	@Override
+	public BaseIntEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+		return convert(rs.getInt(columnIndex));
+	}
+
+	@Override
+	public BaseIntEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+		return convert(cs.getInt(columnIndex));
+	}
+
+	public BaseIntEnum convert(int code) {
+		for (BaseIntEnum enumBaseInterface : type.getEnumConstants()) {
+			if (enumBaseInterface.getCode() == code) {
+				return enumBaseInterface;
+			}
+		}
+		return null;
+	}
+}

+ 60 - 0
src/main/java/com/ym/mec/collectfee/common/dao/StringEnumTypeHandler.java

@@ -0,0 +1,60 @@
+package com.ym.mec.collectfee.common.dao;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+
+/**
+ * 枚举类转换器
+ * @author pengdc
+ */
+@SuppressWarnings("rawtypes")
+public class StringEnumTypeHandler extends BaseTypeHandler<BaseStringEnum> {
+
+	private Class<BaseStringEnum> type;
+
+	public StringEnumTypeHandler(Class<BaseStringEnum> type) {
+		if (type == null)
+			throw new IllegalArgumentException("Type argument cannot be null");
+		this.type = type;
+	}
+
+	@Override
+	public void setNonNullParameter(PreparedStatement ps, int i, BaseStringEnum parameter, JdbcType jdbcType) throws SQLException {
+		if (jdbcType != null) {
+			ps.setString(i, parameter.getName() + "");
+		} else {
+			ps.setObject(i, parameter.getName());
+		}
+	}
+
+	@Override
+	public BaseStringEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
+		return convert(rs.getString(columnName));
+	}
+
+	@Override
+	public BaseStringEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
+		return convert(rs.getString(columnIndex));
+	}
+
+	@Override
+	public BaseStringEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
+		return convert(cs.getString(columnIndex));
+	}
+
+	public BaseStringEnum convert(String name) {
+		for (BaseStringEnum enumBaseInterface : type.getEnumConstants()) {
+			if (StringUtils.equals(StringUtils.chomp(name), enumBaseInterface.getName())) {
+				return enumBaseInterface;
+			}
+		}
+		return null;
+	}
+
+}

+ 151 - 0
src/main/java/com/ym/mec/collectfee/common/page/PageInfo.java

@@ -0,0 +1,151 @@
+/**
+ * PageInfo.java 
+ * Copyright © 2015-2015
+ * 
+ * @author pengdc
+ * @create 2015年7月14日
+ */
+package com.ym.mec.collectfee.common.page;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 分页对象
+ */
+public class PageInfo<T> implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -5951140453033647399L;
+
+	private int pageNo;
+	private int offset;
+	private int limit;
+	private int total = 0;
+	private int totalPage = 0;
+
+	/**
+	 * 分页信息
+	 */
+	protected List<T> rows = new ArrayList<T>();
+
+	protected List<T> footer = new ArrayList<T>();
+
+	/** 默认构造函数 */
+	public PageInfo() {
+	}
+
+	public PageInfo(Integer pageNo) {
+		if (pageNo == null || pageNo < 1)
+			pageNo = 1;
+		this.setPageNo(pageNo);
+	}
+
+	/** 构造函数 */
+	public PageInfo(Integer pageNo, int pageSize) {
+		if (pageNo == null || pageNo < 1)
+			pageNo = 1;
+		this.setPageNo(pageNo);
+		this.limit = pageSize;
+		this.offset = (pageNo - 1) * limit;
+	}
+
+	/**
+	 * 是否还有上一页
+	 * @return
+	 */
+	public boolean hasPre() {
+		return (pageNo > 1);
+	}
+
+	/**
+	 * 是否还有下一页.
+	 */
+	public boolean hasNext() {
+		return (pageNo < totalPage);
+	}
+
+	/**
+	 * 取得上页的页号, 序号从1开始. 当前页为首页时返回首页序号.
+	 */
+	public int getPrePage() {
+		if (hasPre()) {
+			return pageNo - 1;
+		} else {
+			return pageNo;
+		}
+	}
+
+	/**
+	 * 取得下页的页号, 序号从1开始. 当前页为尾页时仍返回尾页序号.
+	 */
+	public int getNextPage() {
+		if (hasNext()) {
+			return pageNo + 1;
+		} else {
+			return pageNo;
+		}
+	}
+
+	public int getPageNo() {
+		return pageNo;
+	}
+
+	public void setPageNo(int pageNo) {
+		if (pageNo > 0) {
+			this.pageNo = pageNo;
+		}
+	}
+
+	public int getOffset() {
+		return offset;
+	}
+
+	public void setOffset(int offset) {
+		this.offset = offset;
+	}
+
+	public int getLimit() {
+		return limit;
+	}
+
+	public void setLimit(int limit) {
+		this.limit = limit;
+	}
+
+	public void setTotalPage(int totalPage) {
+		this.totalPage = totalPage;
+	}
+
+	public int getTotalPage() {
+		return totalPage;
+	}
+
+	public int getTotal() {
+		return total;
+	}
+
+	public void setTotal(int total) {
+		this.total = total;
+	}
+
+	public List<T> getRows() {
+		return rows;
+	}
+
+	public void setRows(List<T> rows) {
+		this.rows = rows;
+	}
+
+	public List<T> getFooter() {
+		return footer;
+	}
+
+	public void setFooter(List<T> footer) {
+		this.footer = footer;
+	}
+
+}

+ 88 - 0
src/main/java/com/ym/mec/collectfee/common/page/QueryInfo.java

@@ -0,0 +1,88 @@
+/**
+ * QueryInfo.java 
+ * Copyright © 2015-2015
+ * 
+ * @author pengdc
+ * @create 2015年7月14日
+ */
+package com.ym.mec.collectfee.common.page;
+
+/**
+ * 查询对象基类
+ */
+public class QueryInfo {
+	/**
+	 * 默认当前页码
+	 */
+	private int page = 1;
+	/**
+	 * 默认页码大小
+	 */
+	private int rows = 20;
+	/**
+	 * 默认排序列
+	 */
+	private String sort = "create_on_";
+	/**
+	 * 默认排序方向
+	 */
+	private String order = "desc";
+	
+	private String search;
+	
+	public String getSearch() {
+		return search;
+	}
+
+	public void setSearch(String search) {
+		this.search = search;
+	}
+
+	public QueryInfo(){}
+	
+	public QueryInfo(int page, int rows, String sort, String order) {
+		super();
+		this.page = page;
+		this.rows = rows;
+		this.sort = sort;
+		this.order = order;
+	}
+	
+	public QueryInfo(int page, int rows) {
+		super();
+		this.page = page;
+		this.rows = rows;
+	}
+
+	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 String getSort() {
+		return sort;
+	}
+
+	public void setSort(String sort) {
+		this.sort = sort;
+	}
+
+	public String getOrder() {
+		return order;
+	}
+
+	public void setOrder(String order) {
+		this.order = order;
+	}
+}

+ 74 - 0
src/main/java/com/ym/mec/collectfee/common/service/BaseService.java

@@ -0,0 +1,74 @@
+package com.ym.mec.collectfee.common.service;
+
+/**
+ * GenericService.java 
+ * Copyright © 2015-2015
+ * 
+ * @author pengdc
+ * @create 2015年7月13日
+ */
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import com.ym.mec.collectfee.common.page.PageInfo;
+import com.ym.mec.collectfee.common.page.QueryInfo;
+
+public interface BaseService<PK extends Serializable, T> {
+	/**
+	 * 通过主键id获取对象
+	 * @author pengdc
+	 * @param id
+	 * @return T
+	 */
+	public T get(final PK id);
+
+	/**
+	 * 更新实体对象
+	 * @author pengdc
+	 * @param bean
+	 * @return int
+	 */
+	public int update(T bean);
+
+	/**
+	 * 通过主键id删除对象
+	 * @author pengdc
+	 * @param id
+	 * @return int
+	 */
+	public int delete(final PK id);
+
+	/**
+	 * 写入实体对象
+	 * @author pengdc
+	 * @param bean
+	 * @return int
+	 */
+	public long insert(T bean);
+
+	/**
+	 * 通过参数查找所有结果集
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public List<T> findAll(Map<String, Object> params);
+
+	/**
+	 * 通过参数查找结果集,适合分页场景
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public PageInfo<T> queryPage(QueryInfo queryInfo);
+
+	/**
+	 * 通过参数查找结果集数目
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public int findCount(Map<String, Object> params);
+	
+}

+ 109 - 0
src/main/java/com/ym/mec/collectfee/common/service/impl/BaseServiceImpl.java

@@ -0,0 +1,109 @@
+package com.ym.mec.collectfee.common.service.impl;
+
+/**
+ * GenericServiceImpl.java 
+ * Copyright © 2015-2015
+ * 
+ * @author pengdc
+ * @create 2015年7月13日
+ */
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.ym.mec.collectfee.common.dao.BaseDAO;
+import com.ym.mec.collectfee.common.page.PageInfo;
+import com.ym.mec.collectfee.common.page.QueryInfo;
+import com.ym.mec.collectfee.common.service.BaseService;
+import com.ym.mec.collectfee.utils.MapUtil;
+
+/**
+ * SERVICE操作基类
+ * @param <PK>
+ * @param <T>
+ */
+public abstract class BaseServiceImpl<PK extends Serializable, T> implements BaseService<PK, T> {
+
+	public abstract BaseDAO<PK, T> getDAO();
+
+	/**
+	 * 通过主键id加载对象
+	 * @param id
+	 * @return
+	 */
+	public T get(final PK id) {
+		return this.getDAO().get(id);
+	}
+
+	/**
+	 * 更新实体对象
+	 * @param bean
+	 * @return int
+	 */
+	public int update(T bean) {
+		return this.getDAO().update(bean);
+	}
+
+	/**
+	 * 通过主键id删除对象
+	 * @param id
+	 * @return int
+	 */
+	public int delete(final PK id) {
+		return this.getDAO().delete(id);
+	}
+
+	/**
+	 * 写入实体对象
+	 * @param bean
+	 * @return int
+	 */
+	public long insert(T bean) {
+		return this.getDAO().insert(bean);
+	}
+
+	/**
+	 * 通过参数查找所有结果集
+	 * @param params
+	 * @return
+	 */
+	public List<T> findAll(Map<String, Object> params) {
+		return this.getDAO().findAll(params);
+	}
+
+	/**
+	 * 通过参数查找结果集,适合分页场景
+	 * @param queryInfo
+	 * @return
+	 */
+	public PageInfo<T> queryPage(QueryInfo queryInfo) {
+		PageInfo<T> pageInfo = new PageInfo<T>(queryInfo.getPage(), queryInfo.getRows());
+		Map<String, Object> params = new HashMap<String, Object>();
+		MapUtil.populateMap(params, queryInfo);
+		
+		List<T> dataList = null;
+		int count = this.findCount(params);
+		if (count > 0) {
+			pageInfo.setTotal(count);
+			params.put("offset", pageInfo.getOffset());
+			dataList = this.getDAO().queryPage(params);
+		}
+		if (count == 0) {
+			dataList = new ArrayList<T>();
+		}
+		pageInfo.setRows(dataList);
+		return pageInfo;
+	}
+
+	/**
+	 * 通过参数查找结果集数目
+	 * @author pengdc
+	 * @param params
+	 * @return
+	 */
+	public int findCount(Map<String, Object> params) {
+		return this.getDAO().findCount(params);
+	}
+}

+ 98 - 0
src/main/java/com/ym/mec/collectfee/utils/MapUtil.java

@@ -0,0 +1,98 @@
+package com.ym.mec.collectfee.utils;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class MapUtil {
+
+	private static final Object[] EMPTY_ARRAY = {};
+
+	/**
+	* 将一个bean转换成map
+	* @param map
+	* @param bean
+	* @return
+	*/
+	public static Map<String, Object> populateMap(Map<String, Object> map, Object bean) {
+		return populateMap(map, bean, null);
+	}
+
+	/**
+	 * 假设prefix=detail.,bean带有一个属性name,则map中将有一个项:
+	 * key=detail.name,value为bean的name属性值。
+	 */
+	public static Map<String, Object> populateMap(Map<String, Object> map, Object bean, String prefix) {
+		boolean withoutPrefix = StringUtils.isBlank(prefix);
+
+		try {
+			Method[] methods = bean.getClass().getMethods();
+			for (int i = 0; i < methods.length; i++) {
+				String methodName = methods[i].getName();
+				Class<?>[] pts = methods[i].getParameterTypes();
+				Class<?> rt = methods[i].getReturnType();
+
+				if (methodName.startsWith("get") && pts.length == 0 && !Void.class.equals(rt)) {
+					String propName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
+					if ("class".equals(propName)) {
+						continue;
+					}
+
+					String key = withoutPrefix ? propName : prefix + propName;
+
+					Object value = methods[i].invoke(bean, EMPTY_ARRAY);
+					if (value != null) {
+						map.put(key, value);
+					}
+				}
+			}
+
+			return map;
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * map to javabean
+	 * @param clazz
+	 * @param map
+	 * @return
+	 * @throws IllegalArgumentException 
+	 * @throws IllegalAccessException 
+	 * @throws IntrospectionException 
+	 * @throws InstantiationException 
+	 */
+	@SuppressWarnings("rawtypes")
+	public static <T> T mapToJavaBean(Class<T> clazz, Map map) throws IllegalAccessException, IllegalArgumentException, IntrospectionException,
+			InstantiationException {
+		T obj = null;
+		BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+		obj = clazz.newInstance();
+		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+		for (int i = 0; i < propertyDescriptors.length; i++) {
+			PropertyDescriptor descriptor = propertyDescriptors[i];
+			String propertyName = descriptor.getName();
+			if (map.containsKey(propertyName)) {
+				Object value = map.get(propertyName);
+				if ("".equals(value)) {
+					value = null;
+				}
+				Object[] args = new Object[1];
+				args[0] = value;
+				try {
+					descriptor.getWriteMethod().invoke(obj, args);
+				} catch (InvocationTargetException e) {
+					System.out.println("params poxy failed");
+				}
+			}
+		}
+		return (T) obj;
+	}
+}

+ 21 - 0
src/main/resources/config/mybatis/Global.mapper.xml

@@ -0,0 +1,21 @@
+<?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="global">
+
+	<sql id="limit">
+		<if test="offset != null">
+			 limit #{offset},#{rows}
+		</if>
+	</sql>
+
+	<sql id="orderby">
+		<if test="sort != null and sort != ''">
+			 ORDER BY ${sort}
+			 <if test="order != null and order != ''">
+			 	${order}
+			 </if>
+		</if>
+	</sql>	
+ </mapper>

+ 196 - 0
src/main/resources/logback-spring.xml

@@ -0,0 +1,196 @@
+<?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">
+
+    <!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
+
+    <contextName>logback</contextName>
+    <!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
+    <property name="log.path" value="D:/nmyslog/nmys" />
+
+    <!-- 彩色日志 -->
+    <!-- 彩色日志依赖的渲染类 -->
+    <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}}"/>
+
+
+    <!--输出到控制台-->
+    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+        <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+            <level>info</level>
+        </filter>
+        <encoder>
+            <Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
+            <!-- 设置字符集 -->
+            <charset>UTF-8</charset>
+        </encoder>
+    </appender>
+
+
+    <!--输出到文件-->
+
+    <!-- 时间滚动输出 level为 DEBUG 日志 -->
+    <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${log.path}/log_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/log-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>
+
+    <!-- 时间滚动输出 level为 INFO 日志 -->
+    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${log.path}/log_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/log-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>
+
+    <!-- 时间滚动输出 level为 WARN 日志 -->
+    <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${log.path}/log_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/log-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>
+
+
+    <!-- 时间滚动输出 level为 ERROR 日志 -->
+    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 正在记录的日志文件的路径及文件名 -->
+        <file>${log.path}/log_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/log-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级别:
+     -->
+
+
+    <!--
+        root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
+        level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
+        不能设置为INHERITED或者同义词NULL。默认是DEBUG
+        可以包含零个或多个元素,标识这个appender将会添加到这个logger。
+    -->
+
+    <!--开发环境:打印控制台-->
+    <springProfile name="dev">
+        <logger name="com.nmys.view" 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>
+
+    <!--生产环境:输出到文件-->
+    <!--<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>