星空网 > 软件开发 > Java

spring 笔记1: mvn 中Controller方法的参数不能是嵌套类(内部类)。

最近做spring开发,个人认为,Controller和客户端js通讯时传递的参数类 只使用某几个方法,为了减少对其他功能的影响,想把参数类定义为Controller类的

嵌套类(内部类)。但是实践发现不行。

系统会报错:

Servlet.service() for servlet [kingkoo] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.itl.wms.mvc.systemsetting.POQCSettingController$QueryParameter]: No default constructor found; nested exception is java.lang.NoSuchMethodException: ***************Controller$嵌套类.<init>()] with root cause
java.lang.NoSuchMethodException: com.itl.wms.mvc.systemsetting.Controller$嵌套类.<init>()

 

提示嵌套类没有空参数的构造函数。虽然我已定义类的空构造函数。

因为spring查找参数类型的构造函数时,指明要找一个空参数的构造函数:

return instantiateClass(clazz.getDeclaredConstructor()); //org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
但是,java里面,嵌套类是没有空参数的构造函数的:
public class App {

public class Nest
{
public Nest(){}

}

public static void main(String[] args) throws Exception {

NestClassConstrunct();
}

private static void NestClassConstrunct()
{
java.lang.Class c= Nest.class;
Constructor<?>[] cc= c.getConstructors();
Parameter[] p;
for (int i = 0; i < cc.length; i++) {
System.out.println(cc[i].toString());
p=cc[i].getParameters();
for (int j = 0; j < p.length; j++) {
System.out.println(p[j].getName()+":"+p[j].getParameterizedType().toString());
}
}
}

输出:

public App$Nest(App)
arg0:class App

 

 

so,只能把参数类移动到一个指定的包里面了。

请高手指正。

 




原标题:spring 笔记1: mvn 中Controller方法的参数不能是嵌套类(内部类)。

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

台湾海运港口:https://www.goluckyvip.com/tag/98997.html
广州海口海运:https://www.goluckyvip.com/tag/98998.html
漳州海运运输:https://www.goluckyvip.com/tag/98999.html
跨境贸易物流:https://www.goluckyvip.com/tag/99.html
创建礼物指南:https://www.goluckyvip.com/tag/990.html
Joom:https://www.goluckyvip.com/tag/9900.html
TikTok斥资210万美元游说美国参议院阻止法案通过 :https://www.goluckyvip.com/news/188220.html
北京飞机票查询(快速查询北京至各地机票价格和航班信息):https://www.vstour.cn/a/366178.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流