我得到以下建议: -
@Before(value="@annotation(loggable)", argNames="joinPoint, loggable")
public void before(JoinPoint joinPoint, Loggable loggable) {
Class<? extends Object> clazz = joinPoint.getTarget().getClass();
MethodSignature methodSignature = (MethodSignature) joinPoint
.getSignature();
Method method = methodSignature.getMethod();
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
RequestMapping myAnnotation = method
.getAnnotation(RequestMapping.class);
CodeSignature codeSignature = (CodeSignature) joinPoint
.getSignature();
String[] argNames = codeSignature.getParameterNames();
logger.info(".....");
}
Run Code Online (Sandbox Code Playgroud)
在类LoggerAspect中:
package net.prcins.esales.web.aspects;
import java.lang.reflect.Method;
import net.prcins.esales.aspect.IRequestLogger;
import net.prcins.esales.log.annotation.Loggable;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.CodeSignature;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; …Run Code Online (Sandbox Code Playgroud) 尝试对控制器包中的所有请求方法(所有 GET 和 POST)调用 around 建议。该建议不适用于请求方法。下面是我的控制器和方面建议方法。
此外,我需要打印请求映射参数,如方法类型(Get 或 Post)和请求的 URL。
控制器类:
package net.prc.sales.web.controller;
// imports
@SessionAttributes({Dictionary.FORM_DRIVER_INFO})
@Controller
public class CustomerInfoController {
@RequestMapping(value = Dictionary.URL_QUOTE_CUSTOMER_INFO, method = RequestMethod.GET)
public ModelAndView viewEsCustInfo(Model model, HttpSession session) throws SessionExpiredException {
ModelAndView mav = new ModelAndView();
// ...
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
方面建议:
@Around("net.prc.sales.web.controller.*.*(..) && " + "@annotation(RequestMapping)")
public void ourAroundAdvice(ProceedingJoinPoint method) {
System.out.println("Before-Advice Part:This is called before the method exceution.\n");
try {
method.proceed();
System.out.println("After-Returning-Advice Part: This is called after the method returns nomally.\n");
} …Run Code Online (Sandbox Code Playgroud) 我在使用Jackson反序列化JSON字符串时遇到问题.我得到错误:com.fasterxml.jackson.databind.JsonMappingException:找到了类型没有合适的构造[简单类型,类RatingDMO]:无法从JSON对象实例化(需要添加/启用类型的信息?)
我将字段映射到JSON文件,并且它的参数可用作属性并具有相同的类型.
注意: - 如果我提供no-arg构造函数(仅用于检查它是否有效),则测试有效.
我无法在代码中提供/保留默认构造函数,因为我在模型中有很少的最终字段.
mapper.readValue(new File("ratingRequest.json"),RatingDMO.class);
JSON文件: -
{
"company": "Test",
"state": "NJ",
"lob": "PA",
"channel": "IA",
"username": "GlobalBatchUser",
"password": "GlobalBatchUser",
"policyNumber": "Test",
"policyKey": 7267,
"transactionType": "Quote",
"evaluationType": null,
"clientID": null,
"policyTerm": "6",
"effectiveDate": "01/01/1980",
"policyXML": null,
"firstName": null,
"lastName": null,
"businessName": null,
"city": null,
"zip": null,
"effectiveDtStart": "06/06/2013",
"effectiveDtEnd": "06/06/2014",
"searchType": "uw1",
"uuid": null,
"policyStatusCodes": [],
"eAdvisorCoverages": {},
"customCoverages": {},
"defaultCoverages": {},
"action": null,
"type": null,
"selectedCoverage": null,
"motorClubMember": true,
"selectedSubCoveres": null,
"customRated": true,
"policyDMO": {
"policyKey": …Run Code Online (Sandbox Code Playgroud)