例外情况如下: 严重:Servlet [hello]的Servlet.service()在路径[/ Spring_MVC]的上下文中引发异常[请求处理失败;嵌套异常是java.lang.IllegalArgumentException:找不到类型的返回值的转换器:class com.spring.mvc.model.User] with root cause java.lang.IllegalArgumentException:找不到类型的返回值的转换器:class com.spring.mvc.model.User
源代码如下: UserController.java
@Controller
@RequestMapping("/user")
public class UserController {
private Map<String,User> users = new HashMap <String, User>();
public UserController(){
users.put("wang", new User("wang","pwang","wang a bo","123"));
users.put("chen", new User("chen","pChen","Chen Lin","1e23"));
}
@RequestMapping(value="{userName}",method=RequestMethod.GET, params="json")
@ResponseBody
public User show(@PathVariable String userName) {
return users.get(userName);
}
}
User.java
public class User {
@NotEmpty(message="User Name not null!!!")
private String userName;
@Size(min=6,max=12,message="Password need 6 to 12 Character!!!")
private String passWord;
private String nickName;
@Email(message="Email Fromat invalide!!")
private String email;
public User(){
}
public User(String userName, String passWord, String nickName, String email) {
super();
this.userName = userName;
this.passWord = passWord;
this.nickName = nickName;
this.email = email;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
弹簧4.3.5释 同时杰克逊 - 全1.9.4.jar
答案 0 :(得分:0)
我用下面的罐子替换了jar jackon-all-1.9.4.jar。这个问题已经解决。 杰克逊 - 数据绑定 - 2.5.0.jar 杰克逊核心2.5.0.jar 杰克逊 - 注解-2.5.0.jar