PhantomThief / model-view-builder

Other
93 stars 16 forks source link

cannot found model's view #6

Open qiaohui opened 6 years ago

qiaohui commented 6 years ago

https://github.com/qiaohui/credit-card

2017-11-09-17:58:03.810 INFO [restartedMain]-com.pay.card.utils.ApiHelper:67>>register view [CreditBankView] for model [CreditBank] with buildContext.

启动时,model view 会有 register。

但是 api 调用时会找不到 view:

cannot found model's view:class com.pay.card.model.CreditBank 2017-11-09-17:58:17.013 ERROR [http-nio-8080-exec-1]-org.apache.juli.logging.DirectJDKLog:181>>Servlet.service() for servlet [dispatcherServlet] in context with path [/credit-card] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null at com.github.phantomthief.view.mapper.impl.DefaultViewMapperImpl.map(DefaultViewMapperImpl.java:32) at com.github.phantomthief.view.mapper.ViewMapper.lambda$map$0(ViewMapper.java:16)

帮忙看看是不是我把CardBuildContext使用错了,谢谢!

qiaohui commented 6 years ago

基于反射的 viewmapper 的设置这里有个条件判断一直是 false: if (parameterTypes.length == 2 && parameterTypes[1] == BuildContext.class) 发现其中条件 parameterTypes[1] == BuildContext.class永远是false,估计不能这么判断, 所以测试时我把这个条件去掉,貌似还是在 map 时异常,找不到对应的view: apiHelper.getViewMapper().map(rv, buildContext)

PhantomThief commented 6 years ago

ViewMapper建议你自己根据你的项目实现,或者其实自己直接map,viewmapper在jdk8下其实用处不大,就是一个自动根据类型map的实现,可以不用,只用model-builder就可以了。

qiaohui commented 6 years ago

也好,貌似orika这个包就是做深度beanclass复制

hai046 commented 6 years ago

刚开始我用这个也是出现scan不到的问题,后来发现分析发现构造函数有特殊要求,不过用这么几年太顺了,以至于我想改造成注解模式scan也搁置了。 天船老师能不能在开源点其他的东西,我等着给你star呢 😆

PhantomThief commented 6 years ago

@hai046 老了……开不动了……