想实现一个功能,就是记录用户的操作日志
想用aop加自定义注解实现
Controller
@SupplierLog(event = "获取订单列表")
@RequestMapping("/getOrderList.do")
public Map getOrderList(HttpSession session,@RequestBody Map param) {
}
AOP
@Pointcut("@annotation(com.hanzhisoft.tender.annotation.SupplierLog)")
public void logPointCut(){
}
@Before("logPointCut() && @annotation(supplierLog)")
public void before(SupplierLog supplierLog) throws Throwable {
SupplierUser user = (SupplierUser) session.getAttribute("currUser");
Map<Object, Object> map = new HashMap<>();
map.put("log_pk", UUIDUtil.getUUID().toUpperCase());
map.put("userid", user.getUserid());
map.put("cusname", user.getSupplireName());
map.put("ip_address", request.getRemoteAddr());
map.put("pk_eppuser", user.getPk_eppuser());
map.put("event", supplierLog.event());
System.out.println(map);
System.out.println("切面执行完毕");
}
在Controller的方法中加已经可以实现了。
但是由于项目比较旧,有很多功能是用servlet实现的,此时想在doPost中添加自定义注解,发现并不生效,就算把Servlet交给Spring管理也不能实现。
@SupplierLog(event = "竞价中心")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml;charset=utf-8");
request.setCharacterEncoding("utf-8");