升级代码结构,采用Maven来管理jar包(10)
This commit is contained in:
116
src/main/java/com/jsh/base/BaseAction.java
Normal file
116
src/main/java/com/jsh/base/BaseAction.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package com.jsh.base;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
import com.jsh.model.po.Basicuser;
|
||||
import com.jsh.service.basic.LogIService;
|
||||
/**
|
||||
* struts2工具类
|
||||
* @author jishenghua qq752718920
|
||||
* struts2 base action 一些常用方法获取
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T>
|
||||
{
|
||||
public LogIService logService;
|
||||
|
||||
/**
|
||||
* 操作日志使用 是否成功表示
|
||||
*/
|
||||
public String tipMsg = "成功";
|
||||
|
||||
/**
|
||||
* 操作日志使用 是否成功表示 0 ==成功 1==失败
|
||||
*/
|
||||
public short tipType = 0;
|
||||
|
||||
public void setLogService(LogIService logService)
|
||||
{
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取session
|
||||
* @return
|
||||
*/
|
||||
public static Map<String,Object> getSession()
|
||||
{
|
||||
return ActionContext.getContext().getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取request
|
||||
* @return
|
||||
*/
|
||||
public static HttpServletRequest getRequest()
|
||||
{
|
||||
return ServletActionContext.getRequest();
|
||||
}
|
||||
/**
|
||||
* 获取response
|
||||
* @return response
|
||||
*/
|
||||
public static HttpServletResponse getResponse()
|
||||
{
|
||||
return ServletActionContext.getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加错误信息
|
||||
* @param anErrorMessage
|
||||
*/
|
||||
public void addActionError(String anErrorMessage)
|
||||
{
|
||||
super.addActionError(anErrorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加消息
|
||||
* @param aMessage
|
||||
*/
|
||||
public void addActionMessage(String aMessage)
|
||||
{
|
||||
clearErrorsAndMessages();
|
||||
super.addActionMessage(aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字段错误
|
||||
* @param fieldName
|
||||
* @param errorMessage
|
||||
*/
|
||||
public void addFieldError(String fieldName, String errorMessage)
|
||||
{
|
||||
clearErrorsAndMessages();
|
||||
super.addFieldError(fieldName, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录用户信息
|
||||
* @return 登录用户对象
|
||||
*/
|
||||
public Basicuser getUser()
|
||||
{
|
||||
return (Basicuser)getSession().get("user");
|
||||
}
|
||||
|
||||
/**
|
||||
* 回写客户端数据
|
||||
* @throws IOException
|
||||
*/
|
||||
public void toClient(String jsonData) throws IOException
|
||||
{
|
||||
HttpServletResponse response = ServletActionContext.getResponse();
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.getWriter().print(jsonData);
|
||||
}
|
||||
}
|
||||
140
src/main/java/com/jsh/base/BaseDAO.java
Normal file
140
src/main/java/com/jsh/base/BaseDAO.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package com.jsh.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
import com.jsh.util.PageUtil;
|
||||
import com.jsh.util.SearchConditionUtil;
|
||||
/**
|
||||
* 基础dao
|
||||
* @author ji_sheng_hua qq:752718920
|
||||
*/
|
||||
public class BaseDAO<T> extends HibernateDaoSupport implements BaseIDAO<T>
|
||||
{
|
||||
protected Class<T> entityClass;
|
||||
|
||||
public void setPoJoClass(Class<T> c)
|
||||
{
|
||||
this.entityClass = c;
|
||||
}
|
||||
|
||||
protected Class<T> getEntityClass()
|
||||
{
|
||||
return this.entityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Serializable create(T t) throws DataAccessException
|
||||
{
|
||||
return this.getHibernateTemplate().save(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(T t) throws DataAccessException
|
||||
{
|
||||
this.getHibernateTemplate().delete(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(Long objID) throws DataAccessException
|
||||
{
|
||||
return (T) this.getHibernateTemplate().get(getEntityClass(), objID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(T t) throws DataAccessException
|
||||
{
|
||||
this.getHibernateTemplate().update(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDelete(String objIDs) throws DataAccessException
|
||||
{
|
||||
this.getHibernateTemplate().bulkUpdate("delete from " + getEntityClass().getName() + " where id in ("+ objIDs + ")");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void find(PageUtil<T> pageUtil) throws DataAccessException
|
||||
{
|
||||
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
|
||||
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+
|
||||
SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
|
||||
pageUtil.setTotalCount(query.list().size());
|
||||
|
||||
// 分页查询
|
||||
int pageNo = pageUtil.getCurPage();
|
||||
int pageSize = pageUtil.getPageSize();
|
||||
if (0 != pageNo && 0 != pageSize)
|
||||
{
|
||||
query.setFirstResult((pageNo - 1) * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
}
|
||||
pageUtil.setPageList(query.list());
|
||||
}
|
||||
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Override
|
||||
// public List<T> find(Map<String, Object> conditon)throws DataAccessException
|
||||
// {
|
||||
// return this.getHibernateTemplate().find(" from " + getEntityClass().getName() + " where 1=1 "+ SearchConditionUtil.getCondition(conditon));
|
||||
// }
|
||||
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Override
|
||||
// public List<T> find(String hql) throws DataAccessException
|
||||
// {
|
||||
// return this.getHibernateTemplate().find(" from " + getEntityClass().getName() + " where 1=1 "+ hql);
|
||||
// }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<T> find(Map<String, Object> conditon, int pageSize, int pageNo)throws DataAccessException
|
||||
{
|
||||
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
|
||||
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ SearchConditionUtil.getCondition(conditon));
|
||||
query.setFirstResult((pageNo - 1) * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
return query.list();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<T> find(String hql, int pageSize, int pageNo)throws DataAccessException
|
||||
{
|
||||
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
|
||||
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ hql);
|
||||
query.setFirstResult((pageNo - 1) * pageSize);
|
||||
query.setMaxResults(pageSize);
|
||||
return query.list();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Integer countSum(Map<String, Object> conditon)throws DataAccessException
|
||||
{
|
||||
List<T> dataList = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
|
||||
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ SearchConditionUtil.getCondition(conditon)).list();
|
||||
return dataList ==null?0:dataList.size();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Integer countSum(String hql) throws DataAccessException
|
||||
{
|
||||
List<T> dataList = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
|
||||
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ hql).list();
|
||||
return dataList ==null?0:dataList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(T t) throws DataAccessException
|
||||
{
|
||||
this.getHibernateTemplate().save(t);
|
||||
}
|
||||
}
|
||||
124
src/main/java/com/jsh/base/BaseIDAO.java
Normal file
124
src/main/java/com/jsh/base/BaseIDAO.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package com.jsh.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
import com.jsh.util.PageUtil;
|
||||
|
||||
/**
|
||||
* 常用增删改查操作
|
||||
* @author ji-sheng-hua qq752718920
|
||||
* @param <T>
|
||||
*/
|
||||
public interface BaseIDAO<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置操作类对象
|
||||
* @param paramClass
|
||||
*/
|
||||
void setPoJoClass(Class<T> paramClass);
|
||||
|
||||
/**
|
||||
* 增加
|
||||
* @param t 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Serializable create(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 增加
|
||||
* @param t 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void save(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param t 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void delete(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* @param objID ID
|
||||
* @return 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
T get(Long objID)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 修改信息
|
||||
* @param t 要修改的对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void update(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 批量删除信息
|
||||
* @param 以逗号分割的ID
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void batchDelete(String objIDs)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 查找列表
|
||||
* @param pageUtil 分页工具类
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void find(PageUtil<T> pageUtil)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 根据条件查询列表--没有分页信息
|
||||
* @param conditon 查询条件
|
||||
* @return 查询列表数据
|
||||
*/
|
||||
// List<T> find(Map<String,Object> conditon)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 根据hql查询 --没有分页信息
|
||||
* @param hql hibernate查询
|
||||
* @return 查询列表数据
|
||||
*/
|
||||
// List<T> find(String hql)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 根据搜索条件查询--分页
|
||||
* @param conditon 查询条件
|
||||
* @param pageSize 每页个数
|
||||
* @param pageNo 页码
|
||||
* @return 查询列表数据
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
List<T> find(Map<String,Object> conditon,int pageSize,int pageNo)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 根据hql查询--分页
|
||||
* @param hql hibernate查询语句
|
||||
* @param pageSize 每页个数
|
||||
* @param pageNo 页码
|
||||
* @return 查询列表数据
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
List<T> find(String hql,int pageSize,int pageNo)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 查找符合条件的总数
|
||||
* @param conditon
|
||||
* @return
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Integer countSum(Map<String,Object> conditon)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 查找符合条件的总数
|
||||
* @param hql
|
||||
* @return
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Integer countSum(String hql)throws DataAccessException;
|
||||
}
|
||||
109
src/main/java/com/jsh/base/BaseIService.java
Normal file
109
src/main/java/com/jsh/base/BaseIService.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package com.jsh.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
import com.jsh.util.PageUtil;
|
||||
/**
|
||||
* 服务层底层接口
|
||||
* @author ji-sheng-hua qq752718920
|
||||
* @param <T>
|
||||
*/
|
||||
public interface BaseIService<T>
|
||||
{
|
||||
/**
|
||||
* 增加
|
||||
* @param t 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Serializable create(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 增加
|
||||
* @param t 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void save(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param t 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void delete(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id 对象ID
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void delete(Long id)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* @param objID ID
|
||||
* @return 对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
T get(Long objID)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 修改信息
|
||||
* @param t 要修改的对象
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void update(T t)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 批量删除信息
|
||||
* @param 以逗号分割的ID
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void batchDelete(String objIDs)throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 查找列表
|
||||
* @param pageUtil 分页工具类
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
void find(PageUtil<T> pageUtil) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 检查名称是否存在,页面唯一性效验使用
|
||||
* @param filedName 效验的字段名称
|
||||
* @param filedVale 校验值
|
||||
* @param idFiled ID字段名称
|
||||
* @param objectID 修改时对象ID
|
||||
* @return true==存在 false==不存在
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Boolean checkIsNameExist(String filedName,String filedVale,String idFiled,Long objectID) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 检查UserBusiness是否存在,页面唯一性效验使用
|
||||
* @param TypeName 类型名称
|
||||
* @param TypeVale 类型值
|
||||
* @param KeyIdName 关键id
|
||||
* @param KeyIdValue 关键值
|
||||
* @param UBName 关系名称
|
||||
* @param UBValue 关系值
|
||||
* @return true==存在 false==不存在
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Boolean checkIsUserBusinessExist(String TypeName,String TypeVale,String KeyIdName,String KeyIdValue,String UBName,String UBValue) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* 检查UserBusiness是否存在,页面唯一性效验使用
|
||||
* @param TypeName 类型名称
|
||||
* @param TypeVale 类型值
|
||||
* @param KeyIdName 关键id
|
||||
* @param KeyIdValue 关键值
|
||||
* @return true==存在 false==不存在
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException;
|
||||
|
||||
|
||||
|
||||
}
|
||||
141
src/main/java/com/jsh/base/BaseService.java
Normal file
141
src/main/java/com/jsh/base/BaseService.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.jsh.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
import com.jsh.util.JshException;
|
||||
import com.jsh.model.po.Basicuser;
|
||||
import com.jsh.util.PageUtil;
|
||||
/**
|
||||
* 底层服务层
|
||||
* @author ji-sheng-hua qq752718920
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class BaseService<T> implements BaseIService<T>
|
||||
{
|
||||
/**
|
||||
* Dao对象
|
||||
*/
|
||||
private BaseIDAO<T> baseDao;
|
||||
|
||||
protected Class<T> entityClass;
|
||||
|
||||
public void setBaseDao(BaseIDAO<T> baseDao)
|
||||
{
|
||||
this.baseDao = baseDao;
|
||||
setPoJoClass(getEntityClass());
|
||||
}
|
||||
|
||||
protected BaseIDAO<T> getBaseDao()
|
||||
{
|
||||
return this.baseDao;
|
||||
}
|
||||
|
||||
private void setPoJoClass(Class<T> c)
|
||||
{
|
||||
this.baseDao.setPoJoClass(c);
|
||||
}
|
||||
|
||||
protected abstract Class<T> getEntityClass();
|
||||
|
||||
@Override
|
||||
public Serializable create(T t) throws DataAccessException
|
||||
{
|
||||
return baseDao.create(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(T t) throws DataAccessException
|
||||
{
|
||||
baseDao.save(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(T t) throws DataAccessException
|
||||
{
|
||||
baseDao.delete(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) throws DataAccessException
|
||||
{
|
||||
baseDao.batchDelete(id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(Long objID) throws DataAccessException
|
||||
{
|
||||
return baseDao.get(objID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(T t) throws DataAccessException
|
||||
{
|
||||
baseDao.update(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDelete(String objIDs) throws DataAccessException
|
||||
{
|
||||
baseDao.batchDelete(objIDs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void find(PageUtil<T> pageUtil) throws DataAccessException
|
||||
{
|
||||
baseDao.find(pageUtil);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkIsNameExist(String filedName, String filedVale,String idFiled,Long objectID) throws DataAccessException
|
||||
{
|
||||
PageUtil<T> pageUtil = new PageUtil<T>();
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
condition.put(filedName + "_s_eq", filedVale);
|
||||
condition.put(idFiled + "_n_neq", objectID);
|
||||
pageUtil.setAdvSearch(condition);
|
||||
baseDao.find(pageUtil);
|
||||
|
||||
List<T> dataList = pageUtil.getPageList();
|
||||
if(null != dataList && dataList.size() > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkIsUserBusinessExist(String TypeName,String TypeVale,String KeyIdName,String KeyIdValue,String UBName,String UBValue) throws DataAccessException
|
||||
{
|
||||
PageUtil<T> pageUtil = new PageUtil<T>();
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
condition.put(TypeName + "_s_eq", TypeVale);
|
||||
condition.put(KeyIdName + "_s_eq", KeyIdValue);
|
||||
condition.put(UBName + "_s_like", UBValue);
|
||||
pageUtil.setAdvSearch(condition);
|
||||
baseDao.find(pageUtil);
|
||||
|
||||
List<T> dataList = pageUtil.getPageList();
|
||||
if(null != dataList && dataList.size() > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException
|
||||
{
|
||||
PageUtil<T> pageUtil = new PageUtil<T>();
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
condition.put(TypeName + "_s_eq", TypeVale);
|
||||
condition.put(KeyIdName + "_s_eq", KeyIdValue);
|
||||
pageUtil.setAdvSearch(condition);
|
||||
baseDao.find(pageUtil);
|
||||
|
||||
List<T> dataList = pageUtil.getPageList();
|
||||
if(null != dataList && dataList.size() > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
174
src/main/java/com/jsh/base/Log.java
Normal file
174
src/main/java/com/jsh/base/Log.java
Normal file
@@ -0,0 +1,174 @@
|
||||
package com.jsh.base;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* 封装log4j日志信息,打印日志信息类
|
||||
* @author ji/sheng/hua qq_7527.18920
|
||||
* @since 2014-01-22
|
||||
*/
|
||||
public class Log
|
||||
{
|
||||
/**
|
||||
* 根据异常信息获取调用类的信息
|
||||
*/
|
||||
private static final Exception ex = new Exception();
|
||||
|
||||
/**
|
||||
* 获取Log4j实例
|
||||
*/
|
||||
private static final Logger log = Logger.getLogger("jsh");
|
||||
|
||||
/**
|
||||
* Info级别日志前缀
|
||||
*/
|
||||
public static final String LOG_INFO_PREFIX = "==========";
|
||||
|
||||
/**
|
||||
* error级别日志前缀
|
||||
*/
|
||||
public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>";
|
||||
|
||||
/**
|
||||
* debug级别日志前缀
|
||||
*/
|
||||
public static final String LOG_DEBUG_PREFIX = "-----------";
|
||||
|
||||
/**
|
||||
* fatal级别日志前缀
|
||||
*/
|
||||
public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$";
|
||||
|
||||
/**
|
||||
* warn级别日志前缀
|
||||
*/
|
||||
public static final String LOG_WARN_PREFIX = "##########";
|
||||
|
||||
/**
|
||||
* 打印deug日期信息
|
||||
* @param msg 日志信息
|
||||
*/
|
||||
public static void debugFileSync(Object msg)
|
||||
{
|
||||
log.debug(getLogDetail(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印debug异常信息
|
||||
* @param msg 日志信息
|
||||
* @param e 异常堆栈
|
||||
*/
|
||||
public static void debugFileSync(Object msg, Throwable e)
|
||||
{
|
||||
log.debug(getLogDetail(msg), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印info日志信息
|
||||
* @param msg 日志信息
|
||||
*/
|
||||
public static void infoFileSync(Object msg)
|
||||
{
|
||||
log.info(getLogDetail(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印 info日志带异常信息
|
||||
* @param msg 日志信息
|
||||
* @param e 异常堆栈
|
||||
*/
|
||||
public static void infoFileSync(Object msg, Throwable e)
|
||||
{
|
||||
log.info(getLogDetail(msg), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印warn日期信息
|
||||
* @param msg 日志信息
|
||||
*/
|
||||
public static void warnFileSync(Object msg)
|
||||
{
|
||||
log.warn(getLogDetail(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印warn日志信息带异常
|
||||
* @param msg日志信息
|
||||
* @param e 异常堆栈
|
||||
*/
|
||||
public static void warnFileSync(Object msg, Throwable e)
|
||||
{
|
||||
log.warn(getLogDetail(msg), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印error日志信息
|
||||
* @param msg 日志信息
|
||||
*/
|
||||
public static void errorFileSync(Object msg)
|
||||
{
|
||||
log.error(getLogDetail(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印error日志信息带异常
|
||||
* @param msg 日志信息
|
||||
* @param e 异常堆栈
|
||||
*/
|
||||
public static void errorFileSync(Object msg, Throwable e)
|
||||
{
|
||||
log.error(getLogDetail(msg), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印fatal日志信息
|
||||
* @param msg 日志信息
|
||||
*/
|
||||
public static void fatalFileSync(Object msg)
|
||||
{
|
||||
log.fatal(getLogDetail(msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印fatal日志信息带异常
|
||||
* @param msg 日志信息
|
||||
* @param e 异常堆栈
|
||||
*/
|
||||
public static void fatalFileSync(Object msg, Throwable e)
|
||||
{
|
||||
log.fatal(getLogDetail(msg), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼装日志详细信息
|
||||
* @param message 要打印的日志信息
|
||||
* @return 封装后的日志详细信息
|
||||
*/
|
||||
private static synchronized String getLogDetail(Object message)
|
||||
{
|
||||
String msg = "";
|
||||
if (null != message)
|
||||
msg = message.toString();
|
||||
StringBuffer bf = new StringBuffer();
|
||||
try
|
||||
{
|
||||
ex.fillInStackTrace();
|
||||
throw ex;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StackTraceElement[] trace = ex.getStackTrace();
|
||||
//获取异常堆栈中的调用类信息
|
||||
final int pos = 2;
|
||||
bf.append(msg);
|
||||
bf.append(" [class:");
|
||||
bf.append(trace[pos].getClassName());
|
||||
bf.append(" method:");
|
||||
bf.append(trace[pos].getMethodName());
|
||||
bf.append(" line:");
|
||||
bf.append(trace[pos].getLineNumber());
|
||||
bf.append("]");
|
||||
}
|
||||
return bf.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user