package com.util; import java.util.Date; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import com.renmai.db.dao.OperlogsMapper; import com.renmai.db.model.Operlogs; /** * 操作日志工具类 * @author renmai *2011-3-6 */ public class OperLogUtil { public static void log(String loginname,String content,HttpServletRequest request){ try { if (content!=null && content.trim().length()>0) { ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext()); OperlogsMapper mapper=(OperlogsMapper) context.getBean("operlogsMapper"); Operlogs log=new Operlogs(); log.setId(UUID.randomUUID().toString()); log.setContent(content); log.setIp(request.getRemoteAddr()); log.setLoginname(loginname); log.setOpertime(new Date()); //mapper.insert(log); // MybatisSessionFactory.getSession().commit(); } } catch (Exception e) { try { // MybatisSessionFactory.getSession().rollback(); } catch (Exception e1) { e1.printStackTrace(); } e.printStackTrace(); } } }