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(); } } }
时间: 2024-11-06 10:07:54