我有这个代码:
user.setFirstName(requ.getParameter("nombre"));
user.setLastName(requ.getParameter("apellidos"));
user.setEmailAddress(requ.getParameter("email"));
user.persist();
我收到了这个错误:
在组 [javax.validation.groups.Default, ] 约束违规列表:[ ConstraintViolationImpl{interpolatedMessage='no puede ser null', propertyPath=emailAddress 期间,类 [com.springsource.marshall.domain.User] 的验证失败, rootBeanClass=class com.springsource.marshall.domain.User, messageTemplate='{javax.validation.constraints.NotNull.message}'} ConstraintViolationImpl{interpolatedMessage='no puede ser null', propertyPath=password, rootBeanClass=class com. springsource.marshall.domain.User, messageTemplate='{javax.validation.constraints.NotNull.message}'} ConstraintViolationImpl{interpolatedMessage='no puede ser null', propertyPath=firstName, rootBeanClass=class com.springsource.marshall.domain。用户,messageTemplate='{javax.validation.约束.NotNull.message}'}]
我试过了:
User user = new User();
System.out.println(requ.getParameter("email"));
System.out.println(requ.getParameter("nombre"));
System.out.println(requ.getParameter("apellidos"));
user.setFirstName(requ.getParameter("nombre"));
user.setLastName(requ.getParameter("apellidos"));
user.setEmailAddress(requ.getParameter("email"));
user.setPassword("poruesadf");
System.out.println("User:" + user);
user.persist();
我得到:
myemail@hotmail.com myfirstname mylastname set firstname User, nombre:User[firstName=,lastName=,emailAddress=,password=,activationDate=,activationKey=,enabled=,locked=,id=,version=,clientes=,incidencias= ,userRoles=,empresaId=]
我不知道为什么用户的所有参数都为空...
这是我的User_Roo_DbManaged.aj:
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).
package com.springsource.marshall.domain;
import com.springsource.marshall.domain.Cliente;
import com.springsource.marshall.domain.Empresa;
import com.springsource.marshall.domain.Incidencia;
import com.springsource.marshall.domain.User;
import com.springsource.marshall.domain.UserRole;
import java.util.Date;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.springframework.format.annotation.DateTimeFormat;
privileged aspect User_Roo_DbManaged {
@OneToMany(mappedBy = "userId")
private Set<Cliente> User.clientes;
@OneToMany(mappedBy = "userId")
private Set<Incidencia> User.incidencias;
@OneToMany(mappedBy = "userEntry")
private Set<UserRole> User.userRoles;
@ManyToOne
@JoinColumn(name = "empresa_id", referencedColumnName = "id")
private Empresa User.empresaId;
@Column(name = "firstName", length = 99, insertable=false,updatable=false)
private String User.firstName;
@Column(name = "lastName", length = 30, insertable=false,updatable=false)
private String User.lastName;
@Column(name = "password", length = 100, insertable=false,updatable=false)
private String User.password;
@Column(name = "emailAddress", length = 45, insertable=false,updatable=false)
private String User.emailAddress;
@Column(name = "activationDate", insertable=false,updatable=false)
@Temporal(TemporalType.DATE)
@DateTimeFormat(style = "M-")
private Date User.activationDate;
@Column(name = "activationKey", length = 45, insertable=false,updatable=false)
private String User.activationKey;
@Column(name = "enabled", insertable=false,updatable=false)
private Boolean User.enabled;
@Column(name = "locked", insertable=false,updatable=false)
private Boolean User.locked;
public Set<Cliente> User.getClientes() {
return clientes;
}
public void User.setClientes(Set<Cliente> clientes) {
this.clientes = clientes;
}
public Set<Incidencia> User.getIncidencias() {
return incidencias;
}
public void User.setIncidencias(Set<Incidencia> incidencias) {
this.incidencias = incidencias;
}
public Set<UserRole> User.getUserRoles() {
return userRoles;
}
public void User.setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}
public Empresa User.getEmpresaId() {
return empresaId;
}
public void User.setEmpresaId(Empresa empresaId) {
this.empresaId = empresaId;
}
public String User.getFirstName() {
return firstName;
}
public void User.setFirstName(String firstName) {
this.firstName = firstName;
}
public String User.getLastName() {
return lastName;
}
public void User.setLastName(String lastName) {
this.lastName = lastName;
}
public String User.getPassword() {
return password;
}
public void User.setPassword(String password) {
this.password = password;
}
public String User.getEmailAddress() {
return emailAddress;
}
public void User.setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public Date User.getActivationDate() {
return activationDate;
}
public void User.setActivationDate(Date activationDate) {
this.activationDate = activationDate;
}
public String User.getActivationKey() {
return activationKey;
}
public void User.setActivationKey(String activationKey) {
this.activationKey = activationKey;
}
public Boolean User.getEnabled() {
return enabled;
}
public void User.setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Boolean User.getLocked() {
return locked;
}
public void User.setLocked(Boolean locked) {
this.locked = locked;
}
}
有没有人有任何可能的解决方案?
谢谢!!