spring mvc org.springframework.beans.NullValueInNestedPathException错误

来源:互联网 发布:用户数据挖掘 编辑:程序博客网 时间:2024/05/29 12:31

1.最近学习spring mvc的时候 遇到问题百度,本来一个很简单的 问题,但是百度出来的资源真是少;让我明显觉得比android 要少的多;为了社区的繁华,我决定将我遇到的一系列的有意义web问题。都写一个博客,帮助大家解决问题。这个问题很常见。


学习spring mvc的pojo的时候遇到的现在开始贴代码:

html代码:

<form action="/index" >    姓名:<input type="text" name="name"/>    <br/>    年龄:<input type="text" name="age"/>    <br/>    城市<input type="text" name="address.city"/>    <br/>    省份<input type="text" name="address.provice"/>    <br/>    <input type="submit" value="提交"/></form>

User对象代码:
public class User {    public String name;    public int age;    public Address address;    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }    public Address getAddress() {        return address;    }    public void setAddress(Address address) {        this.address = address;    }}


Address类:

public class Address {    public String city;    public String provice;        public Address(String city, String provice){        this.city=city;        this.provice=provice;    }    public String getCity() {        return city;    }    public void setCity(String city) {        this.city = city;    }    public String getProvice() {        return provice;    }    public void setProvice(String provice) {        this.provice = provice;    }}


运行代码:

报错org.springframework.beans.NullValueInNestedPathException: Invalid property 'address' of bean class [com.wxy.company.model.User]: Could not instantiate property type [com.wxy.company.model.Address] to auto-grow nested property path: java.lang.InstantiationException: com.wxy.company.model.Address


就是address 实例化失败:


最后在百度上搜索:发现因为Address 没得空函数的构造方法。

原因就是非空函数的构造方法 无法构建对象。

                                             
0 0
原创粉丝点击