最近做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方法的参数不能是嵌套类(内部类)。的更多相关文章

  1. springmvc中Controller方法的返回值

    1.1 返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. 1.2 返回void 在controller方法形参 ...

  2. 不用注入方式使用Spring管理的对象中的方法,神奇

    在小冷工作中遇到这么一个小问题,当你的业务层对象交给spring管理之后,在普通的类中调用这个类中的方法时候,会有个问题这个类在调用时候会一直返回一个null,而且还会抛出一个空指针异常. 小冷在遇到 ...

  3. SpringMVC的Controller方法的参数不能直接绑定List、Set、Map

    List需要绑定在对象上,而不能直接写在Controller方法的参数中. http://www.iteye.com/topic/973918

  4. CLR via C# 读书笔记---常量、字段、方法和参数

    常量 常量是值从不变化的符号.定义常量符号时,它的值必须能在编译时确定.确定后,编译器将唱两只保存在程序集元数据中.使用const关键字声明常量.由于常量值从不变化,所以常量总是被视为类型定义的一部分 ...

  5. js中settimeout方法加参数

    js中settimeout方法加参数的使用. 简单使用看w3school  里面没有参数调用,  例子: <script type="text/javascript"> ...

  6. Spring 中Controller 获取请求参数的方法笔记

    1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交.若"Content-Type"="application/ ...

  7. Spring MVC中 controller方法返回值

    1.返回ModelAndView 定义ModelAndView对象并返回,对象中可添加model数据.指定view 2.返回String 1.表示返回逻辑视图名 model对象通过 model.add ...

  8. SprimgMVC学习笔记(五)—— Controller方法返回值

    一.返回ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据.指定view. /** * 查询商品列表 * @return */ @R ...

  9. Java学习笔记十一:Java中的方法

    Java中的方法 一:什么是方法: 所谓方法,就是用来解决一类问题的代码的有序组合,是一个功能模块. 学过C语言或者其他语言的应该都知道函数这个东西,在Java中,其实方法就是函数,只不过叫法不同,在 ...

随机推荐

  1. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  2. 百度地图 获取两点坐标之间的驾车距离(非直线距离) c#

    百度接口了解: http://lbsyun.baidu.com/index.php?title=webapi/route-matrix-api-v2 起点与终点为多对多关系,如果你只想取两个坐标,那就 ...

  3. phpv6_css

    global @charset "utf-8"; /* CSS Document */ /*格式化样式*/ body,div,dl,dt,dd,ul,ol,li,h1,h2,h3, ...

  4. EntityFramework 连接字符串

    1. Microsoft SQL Server 2016 LocalDB <connectionStrings> <add name="DefaultConnection& ...

  5. 关于 windows 下 node_modules\node-sass\vendor 的报错解决方法

    项目git clone下来之后,运行npminstall, npm start报错代码如下: ERROR in ENOENT: no such file or directory, scandir ' ...

  6. Qt字符串类——3.字符串的转换

    (1)QString::toInt()函数将字符串转换为整型数值,类似的函数还有toDouble().toFloat().toLong().toLongLong()等.下面举个例子说明其用法: QSt ...

  7. UWP&WP8.1 重新绘制图片 WriteableBitmap用法 图片转byte[]数组,byte[]数组转图片

    ---恢复内容开始--- WriteableBitmap 是UWP和WP8.1绘制图片的,重组图片的最重要方法.方法较为简单,方法多样性. 通过查看文档,WriteableBitmap的继承性是    ...

  8. DOS命令追加符的使用

    @echo off start \\192.168.10.120\常用软件\系统工具\远程客户端\winvnc.exe #打开共享的远程客户端程序 ipconfig /all > d:\disp ...

  9. JS中isPrototypeOf 和hasOwnProperty 的区别 ------- js使用in和hasOwnProperty获取对象属性的区别

    JS中isPrototypeOf 和hasOwnProperty 的区别 1.isPrototypeOf isPrototypeOf是用来判断指定对象object1是否存在于另一个对象object2的 ...

  10. A记录、CNAME、MX记录、NS记录

    1. A记录(IP指向) 又称IP指向,用户可以在此设置子域名并指向到自己的目标主机地址上,从而实现通过域名找到服务器找到相应网页的功能. 说明:指向的目标主机地址类型只能使用IP地址. 2. CNA ...