NutzCN Logo
问答 content-type为application/json时,获取Long的param值出错.
发布于 230天前 作者 qq_046f8286 385 次浏览 复制 上一个帖子 下一个帖子
标签:

错误信息为这个.

2018-04-02 14:37:57  [DEBUG] org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [POST] path=/hrp/kh/customer/controller/mCustomerStore/queryCustomerStoreByIdToRet : MCustomerStoreAction.queryCustomerStoreByIdToRet(MCustomerStoreAction.java:57)
2018-04-02 14:37:57  [DEBUG] org.nutz.ioc.impl.NutIoc.get(NutIoc.java:165) - Get 'mCustomerStoreAction'<class com.fzzl.hrp.kh.customer.controller.MCustomerStoreAction>
2018-04-02 14:38:03  [ERROR] com.sys.framework.exception.WarningException.getExceptionMsg(WarningException.java:42) - Fail to born or cast to 'java.lang.Long'
 by args: []
 because: No suitable Constructor or Factory Method!!
org.nutz.lang.born.BorningException: Fail to born or cast to 'java.lang.Long'
 by args: []
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1008)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.injectObj(ObjConvertImpl.java:218)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:91)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
	at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
	at org.nutz.mvc.adaptor.injector.JsonInjector.get(JsonInjector.java:34)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:288)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
2018-04-02 14:38:03  [WARN] org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/hrp/kh/customer/controller/mCustomerStore/queryCustomerStoreByIdToRet :

通过Restclient 测试.

16 回复

入口方法是怎样的, 发送的内容是怎样的

@wendal 我都截图发你QQ里面了。你看一下。

入口方法:
http://localhost:8080/fzzl/hrp/kh/customer/controller/mCustomerStore/queryCustomerStoreByIdToRet

Content-Type=application/json
正文:{"customerStoreId":123}

没加 @AdaptBy(type=JsonAdapter.class)的样子

@At("/queryCustomerStoreByIdToRet")
	@Ok("json")
	@AdaptBy(type = JsonAdaptor.class)
	public Object queryCustomerStoreByIdToRet(@Param("customerStoreId") Long mCustomerStoreId) {
		BaseResultMap resultMap = new BaseResultMap(true, "添加成功!");
		String test  ="";
		try {
			Object o=customerStoreService.queryCustomerStoreById(DataTypeUtil.toLong(mCustomerStoreId));
			resultMap.setData(o);
		} catch (Exception e) {
			resultMap.setOk(false);
			resultMap.setMessage(WarningException.getExceptionMsg(e));
			logError(e);
		}
		return resultMap;
	}

@wendal 后台代码,加了,一直取不到。

取不到是指报错还是null? 贴当前日志

并不是所有的Long都取不到,但是这种单独出现的Long,就会存在取不到的问题。我开始以为是我前台发送请求的时候有问题,后面我换Restclient测,还是一样存在取不到值的问题。

前面的就是当前显示的日志。

@wendal 顶上有全部日志

018-04-02 14:37:57  [DEBUG] org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [POST] path=/hrp/kh/customer/controller/mCustomerStore/queryCustomerStoreByIdToRet : MCustomerStoreAction.queryCustomerStoreByIdToRet(MCustomerStoreAction.java:57)
2018-04-02 14:37:57  [DEBUG] org.nutz.ioc.impl.NutIoc.get(NutIoc.java:165) - Get 'mCustomerStoreAction'<class com.fzzl.hrp.kh.customer.controller.MCustomerStoreAction>
2018-04-02 14:38:03  [ERROR] com.sys.framework.exception.WarningException.getExceptionMsg(WarningException.java:42) - Fail to born or cast to 'java.lang.Long'
 by args: []
 because: No suitable Constructor or Factory Method!!
org.nutz.lang.born.BorningException: Fail to born or cast to 'java.lang.Long'
 by args: []
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1008)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.injectObj(ObjConvertImpl.java:218)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:91)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
	at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
	at org.nutz.mvc.adaptor.injector.JsonInjector.get(JsonInjector.java:34)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:288)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)

试试这样写, 感觉像个bug,但不确定

@Param("customerStoreId") long mCustomerStoreId

就是Long改成long试试

我之前是long发现不行,然后又改Long,还是有问题。然后我改String,发现传过去的值就变成空字符串了。

那就神奇了,debug一下JsonAdaptor吧,我感觉就没能读到json

问题解决了,是因为引用了org.apache.ibatis.annotations.Param 作为@param的包,造成取参数的时候取得是空,但是能够通过@param("..") map 的形式获取到。
@wendal

... 原来是这样

恩。这个方法里面有很多action方法,一直取值没有错,都没有想到param这个问题上来.自己坑了自己一笔。

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