NutzCN Logo
问答 SLOG before 取方法参数的问题
发布于 2386天前 作者 Leewell1989 2257 次浏览 复制 上一个帖子 下一个帖子
标签:

想在before的时候记录用户名,取参数值得时候报错:
代码:

        @At("/user/login")
	@Ok("json")
	@Slog(tag = "用户登录", before = "用户${args.username}登录", after = "{resp:${re.code}}", error = "登录发生异常:${e.message}")
	public Object login(@Param("username") String userName, @Param("password") String password){

日志:

2018-05-12 20:08:12,674 DEBUG [http-nio-80-exec-3] o.n.i.i.NutIoc#log [113] Get 'slogService'<class com.yuro.log.YlogService>
2018-05-12 20:08:12,674 DEBUG [http-nio-80-exec-3] o.n.i.i.NutIoc#log [113] 	 >> Load definition name=slogService
2018-05-12 20:08:12,674 DEBUG [http-nio-80-exec-3] o.n.i.l.c.ComboIocLoader#log [113] Found IocObject(slogService) in AnnotationIocLoader(packages=[com.yuro])
2018-05-12 20:08:12,675 DEBUG [http-nio-80-exec-3] o.n.i.i.NutIoc#log [113] 	 >> Make...'slogService'<class com.yuro.log.YlogService>
2018-05-12 20:08:12,675 DEBUG [http-nio-80-exec-3] o.n.i.i.ScopeContext#log [113] Save object 'slogService' to [app] 
2018-05-12 20:08:12,675 DEBUG [http-nio-80-exec-3] o.n.i.i.NutIoc#log [113] Get 'log'<interface org.nutz.aop.MethodInterceptor>
2018-05-12 20:08:12,699 DEBUG [http-nio-80-exec-3] o.n.i.i.NutIoc#log [113] Get 'dao'<>
2018-05-12 20:08:12,703 DEBUG [http-nio-80-exec-3] o.n.i.i.NutIoc#log [113] Get 'slogService'<class org.nutz.plugins.slog.service.SlogService>
2018-05-12 20:08:12,716 DEBUG [http-nio-80-exec-3] o.n.p.s.a.SlogAopInterceptor#doLog [96] slog fail
org.nutz.lang.FailToGetValueException: Fail to get value for [[Ljava.lang.Object;]->[username]
	at org.nutz.lang.Mirror.makeGetValueException(Mirror.java:776) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.Mirror.getValue(Mirror.java:839) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.el.opt.object.AccessOpt.calculate(AccessOpt.java:46) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.el.arithmetic.RPN.calculate(RPN.java:55) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.el.arithmetic.RPN.calculate(RPN.java:38) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.el.El.eval(El.java:33) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.plugins.slog.service.SlogService.log(SlogService.java:239) ~[nutz-plugins-slog-1.r.65.jar:na]
	at org.nutz.plugins.slog.aop.SlogAopInterceptor.doLog(SlogAopInterceptor.java:83) [nutz-plugins-slog-1.r.65.jar:na]
	at org.nutz.plugins.slog.aop.SlogAopInterceptor.filter(SlogAopInterceptor.java:66) [nutz-plugins-slog-1.r.65.jar:na]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60) [nutz-1.r.65.jar:1.r.65]
	at com.yuro.credit.handler.SystemHandler$$NUTZAOP.login(SystemHandler.java:1) [nutz-1.r.65.jar:na]
	at com.yuro.credit.handler.SystemHandler$FM$login$66b716e0a026a32e62a39359ab72f329.invoke(SystemHandler.java) [nutz-1.r.65.jar:na]
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31) [nutz-1.r.65.jar:1.r.65]
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202) [nutz-1.r.65.jar:1.r.65]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.23]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.23]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:8.5.23]
	at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:96) [catalina.jar:8.5.23]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [catalina.jar:8.5.23]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [catalina.jar:8.5.23]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:8.5.23]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [catalina.jar:8.5.23]
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) [catalina.jar:8.5.23]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:8.5.23]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [catalina.jar:8.5.23]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-coyote.jar:8.5.23]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:8.5.23]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-coyote.jar:8.5.23]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-coyote.jar:8.5.23]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:8.5.23]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.5.23]
	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101]
Caused by: java.lang.NoSuchMethodException: Fail to find getter for [[Ljava.lang.Object;]->[username]
	at org.nutz.lang.reflect.fast.java.lang.NoSuchMethodException$FC$ab706b0cf40b3b24094a0af312e173b9.invoke(NoSuchMethodException.java) ~[nutz-1.r.65.jar:na]
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.Mirror.born(Mirror.java:1010) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.Lang.makeThrow(Lang.java:153) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.Mirror.getGetter(Mirror.java:264) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.Mirror.getGetter(Mirror.java:210) ~[nutz-1.r.65.jar:1.r.65]
	at org.nutz.lang.Mirror.getValue(Mirror.java:817) ~[nutz-1.r.65.jar:1.r.65]
	... 45 common frames omitted
6 回复

args是数组, 不是map, 如果是jdk8且启用了编译参数-paramters,可以直接写 ${username}

应该是 ${userName}, 方法参数名

嗯,两种写法都试了,都可以。

${args[0]} 和 ${userName}

意思就是取得是参数变量名,不是@Param的名称呗,明白。

通用的,并非只能标在入口方法

添加回复
请先登陆
回到顶部