springboot@ControllerAdvice + RequestBodyAdvice 복호화 도구 구덩이 밟기 기록
2173 단어 springboot
최소 몇 십 편의springboot 복호화와 관련된 강좌를 보았는데, 대체로 @Controller Advice 설명 + RequestBody Advice 인터페이스를 실현했습니다.코드가 복잡하지 않기 때문에 자신의 복호화 차단류를 직접 참고하고 처리했다.그러나 차단에 들어갈 수 없었고 손으로 코드를 두드리는 것이 차단류를 잘못 두드린 줄 알고 다시 인터넷에서 코피 코드를 시도했지만 결과적으로 코드가 정상적으로 작동하지 못했다.그러나github 위에서pull 다른 사람의 코드는 달리기 시작하면 정상적으로 차단할 수 있다.그래서 클래스를 다시 차단합니다. 차단할 수 없습니다.
이유:
Controller층의 수신 파라미터가 @RequestBody를 추가하지 않아서 차단에 들어가지 않았습니다!!!이에 기록합니다
Controller층의 수신 파라미터가 @RequestBody를 추가하지 않아서 차단에 들어가지 않았습니다!!!이에 기록합니다
Controller층의 수신 파라미터가 @RequestBody를 추가하지 않아서 차단에 들어가지 않았습니다!!!이에 기록합니다
코드 붙여넣기
차단 처리 복호화 실현
1. @ControllerAdvice 메모 삽입
2. RequestBodyAdvice 인터페이스 구현
@ControllerAdvice(basePackages = "com.xiaoc.verify.controller")
public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
@Override
public boolean supports(MethodParameter methodParameter, Type type, Class extends HttpMessageConverter>> aClass) {
// , ,
return methodParameter.getMethodAnnotation(DecodeRequest.class) != null ;
}
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class extends HttpMessageConverter>> aClass) throws IOException {
System.out.println("*** ***");
return httpInputMessage;
}
@Override
public Object afterBodyRead(Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class extends HttpMessageConverter>> aClass) {
return o;
}
@Nullable
@Override
public Object handleEmptyBody(@Nullable Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class extends HttpMessageConverter>> aClass) {
return o;
}
}
Controller 레이어
관건은 매개 변수를 받는 @RequestBody 메모입니다.
@ResponseBody
@RequestMapping(value = "/test",method = RequestMethod.POST)
public ReturnVo test(@RequestBody String param) throws Exception{
System.out.println(param);
return ReturnVo.success();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin Springboot -- 파트 14 사용 사례 REST로 전환하여 POST로 JSON으로 전환前回 前回 前回 記事 の は は で で で で で で を 使っ 使っ 使っ て て て て て リクエスト を を 受け取り 、 reqeustbody で 、 その リクエスト の ボディ ボディ を を 受け取り 、 関数 内部 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.