编程知识 cdmana.com

How does the springboot interceptor get the parameters in the serviceimpl method

Now you need to add a method to the maintained project , I don't want to move the original logic, so I think of using interceptors or aop Expand business from all aspects , But you need to get service The parameter or return value in can be , General interceptors take controller Layer of request and response. Find a solution , There are other technologies that can be implemented

## controller@PostMapping("/test")    @ApiOperation(" Test it ")    public QueryResult test(){        String kkk = "2222";        return QueryResult.success( aiLawUnifyFXService.test(kkk));    }## serviceImpl:    @Transactional(rollbackFor = Exception.class,propagation= Propagation.REQUIRED)    @Override    public int test(String kkk) {        int ll = aiEventHandleBaseService.updateAppEventProcessStatus("AI22040710023600002", null,0);        System.out.println("-----------------------------------service return ----------------------------");        return ll;    }##  Jump to the second floor serviceImpl  What you need to get is the of the layer eventId  Parameter or return value i    @Intercept    @Override    public int updateAppEventProcessStatus(String eventId, String handleStatus, String finishStatus) {        System.out.println("---------------222222222--------------------");        int i = aiEventHandleBaseDao.updateAppEventProcessStatus(eventId, handleStatus, finishStatus);        return i;    }##  Here is the interceptor written   But the return is controller Medium @Componentpublic class Ilegalinterceptor implements HandlerInterceptor {    @Autowired    private AiLawUnifyFXService aiLawUnifyFXService;    @Autowired    private AiEventHandleBaseService aiEventHandleBaseService;    @Override    public boolean preHandle(HttpServletRequest request,                             HttpServletResponse response,                             Object handler) {        System.out.println(" Start intercepting  LoginInterceptor.........");        String queryString = request.getQueryString();        System.out.println(queryString);        return true;    }    @Override    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,                           @Nullable ModelAndView modelAndView) {        String eventId = request.getParameter("eventId");        Object eventId1 = request.getAttribute("eventId");        System.out.println(" end  LoginInterceptor.........");        // Business code   For the same thing, the mechanism is written here         String queryString = request.getQueryString();    // aiLawUnifyFXService.update("AI22032216293300003",0);        System.out.println(" end  LoginInterceptor.........1111111111111111");    }    @Override    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,                                @Nullable Exception ex) {        System.out.println(" Complete end  LoginInterceptor.........");    }}



Take the answer :

You said aop 了 , It would be aop Chant


版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2022/134/202205072059338220.html

Scroll to Top