代码-初学springmvc 报错 求助

问题描述

初学springmvc 报错 求助
JSP页面表单信息:
<form action="springmvc/testmodelattribute" method="post">

    id:<input type="hidden" name="id" value="1"> <br>

    username: <input type="text" name="username" value="miwa"> <br>

    email:<input type="text" name="email" value="abc.miwa"> <br>

    age:<input type="text" name="age" value="20"> <br> 

    <input type="submit" value="submit">

springmvc handler 相关代码:
@Controller
@RequestMapping("/springmvc")
public class gloomy {

@ModelAttribute
public void getUser(@RequestParam(value="id ",required = false) Integer id,Map<String , Object> map ){
    if(id != null){
        User user = new User("miwa", id, "123456", "abc.miwa", 20);
        System.out.println("获取一个对象"+user);
        map.put("user", user);
    }
    System.out.println("我在这里");
}

@RequestMapping("/testmodelattribute")
public String  testmodelattribute( User user){
    System.out.println("修改"+user);
    return "success";
}

}
POJO代码:

public class User {
private String username;
private Integer id;
private String password;
private String email;
private int age;
private Adress adress;
public User(String username, Integer id, String password, String email,
        int age) {
    super();
    this.username = username;
    this.id = id;
    this.password = password;
    this.email = email;
    this.age = age;
}
public User(String username, String password, String email, int age) {
    super();
    this.username = username;
    this.password = password;
    this.email = email;
    this.age = age;
}
public Adress getAdress() {
    return adress;
}
public int getAge() {
    return age;
}
public String getEmail() {
    return email;
}
public Integer getId() {
    return id;
}

public String getPassword() {
    return password;
}
public String getUsername() {
    return username;
}
public void setAdress(Adress adress) {
    this.adress = adress;
}
public void setAge(int age) {
    this.age = age;
}
public void setEmail(String email) {
    this.email = email;
}
public void setId(Integer id) {
    this.id = id;
}
public void setPassword(String password) {
    this.password = password;
}
public void setUsername(String username) {
    this.username = username;
}
@Override
public String toString() {
    return "User [username=" + username + ", id=" + id + ", password="
            + password + ", email=" + email + ", age=" + age + "]";
}

异常信息:

    严重: Servlet.service() for servlet [springDispatcherServlet] in context with path [/SpringMVC] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.gloomy.springmvc.pojos.User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.gloomy.springmvc.pojos.User.<init>()] with root cause

java.lang.NoSuchMethodException: com.gloomy.springmvc.pojos.User.()

解决方案

Spring注入属性时通常是根据无参构造函数创建对象,然后调用类的各个属性的getter和setter完成成员变量赋值的。
所以需要User类提供一个无参构造函数。

解决方案二:

SpringMVC报错集中营

解决方案三:

解决方案四:

把那两个super()方法删掉试试,没有继承用super()干嘛?

解决方案五:

nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.gloomy.springmvc.pojos.User]: No default constructor found; 从这条报错信息可以看出是没有事先默认的构造方法,即无参构造方法,你在那个User类里写多一个无参的构造方法看行吗?即pubic User(){}

时间: 2024-09-12 22:40:36

代码-初学springmvc 报错 求助的相关文章

exception-winform程序报错求助(判断查询结果是否为空)

问题描述 winform程序报错求助(判断查询结果是否为空) 小弟初学c#,写了一个数据查询的程序,分别用四个方法实现数据查询结果是否为空的判断,方法1和方法2都可以,但是方法三和方法四一直提示 " 对象的当前状态使该操作无效"异常,请各位大侠给指点下,问题出在哪? 备注:1.oradr.GetString(0)))字段本人用控制台测试是能正确输出相关数据库字段信息的: 2.看到网上说这个错误一般是,数据超过1000条的缘故,但是这个用户数据库里面只有一条数据,所以我也有点头晕,还请各

persistence-初学JPA,报错求助:No Persistence provider for EntityManager named

问题描述 初学JPA,报错求助:No Persistence provider for EntityManager named 报错信息: Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named jpatest at javax.persistence.Persistence.createEntityManager

java定时器 run方法怎么返回值 我要返回result 代码里一直报错 晚生跪求解决

问题描述 java定时器 run方法怎么返回值 我要返回result 代码里一直报错 晚生跪求解决 public VirementResultInfo queryTransaction( final String bank, final TransactionInfo transactionInfo) { // final VirementResultInfo result = null; TimerTask task = new TimerTask() { @Override public v

springmvc报错求解求解啊。

问题描述 springmvc报错求解求解啊. 解决方案 解决方案二: 解决方案三:

一段简单的c代码,一直报错,求大神们指点

问题描述 一段简单的c代码,一直报错,求大神们指点 char * reverse_str(char *s){ char *p = s; char *q = s; char temp = 0; while(*q != ''){ q++; } q--;//前一个字符 while(p < q){ temp = *p; *p = *q; *q = temp; p++; q--; } return s; } 调试之后发现是交换那段循环的问题,不知道问题出在哪,求指点! 解决方案 http://codepa

ndk ndroid tudio jni-AndroidStudio中开发ndk报错,求助!!!

问题描述 AndroidStudio中开发ndk报错,求助!!! D:workspacesAndroidProjectsGISpeechappsrcmainjniHTKLibexcpt.h:20:21: fatal error: crtdefs.h: No such file or directory #include <crtdefs.h> as 的项目中使用ndk 开发,其中有些 c 文件中引用了一些 系统平台下的 h 文件,在 vs2010 中可以调通,但是加入到 jni 中就报错,请问

app-android代码混淆打包报错

问题描述 android代码混淆打包报错 FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':app:shrinkReleaseMultiDexComponents'. > java.io.IOException: The output jar [/root/.jenkins/jobs/Android-PRD/workspace/app/build/intermediates/

cocos2d-x移植到eclipse中main.cpp报错 求助!

问题描述 cocos2d-x移植到eclipse中main.cpp报错 求助!

textview代码中id报错

问题描述 textview代码中id报错 TextView textView = (TextView) findViewById(R.id.mainTextView1); textView.setText("Correct!"); id 报错是什么情况该怎么解决 解决方案 没找到空间,检查下它是不是嵌套在别的控件里了. 解决方案二: 没找到控件,检查下它是不是嵌套在别的控件里了.