[英]Dozer mapping not working for nested object
I was Trying to copy value of StudentRequestForm
class to StudentEntity
class .all values are saved but a classI
field in studentBean
is not saved which is mapped to StudentEntity
classId
.So i want my ClassI value copy to classId 我试图将StudentRequestForm
类的值复制到StudentEntity
类。保存所有值,但不保存studentBean
的classI
字段,该字段映射到StudentEntity
classId
。所以我希望我的ClassI值复制到classId
you can check in below dozer mapping 你可以在下面的推土机映射登记
public class StudentRequestForm {
private StudentModel studentbean;
public StudentModel getStudentbean() {
return studentbean;
}
public void setStudentbean(StudentModel studentbean) {
this.studentbean = studentbean;
}`enter code here`
public class StudentModel {
private int countryId,cityId,stateId,classI;
private String enrollmentId,firstName,lastName,gender,category,pincode,sectionName;
@Entity
@Table(name="students")
public class StudentEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private int age;
private String category;
private String pincode;
private int cityId;
@Column(name="class_id")
private int classId;
@Column(name="country_id")
private int countryId;
@Column(name="first_name")
private String firstName;
private String gender
................... ................ ; ................... ................;
Dozer mapping 推土机映射
<mapping>
<class-a>com.myschool.entity.StudentRequestForm</class-a>
<class-b>com.myschool.entity.StudentEntity</class-b>
<field>
<a>studentbean.classI</a>
<b>classId</b>
</field>
</mapping>
controller methood 控制器
public ModelAndView saveForm(HttpServletRequest request,HttpServletResponse response,StudentRequestForm studentForm){
try{
StudentEntity studententity = mapper.map(studentForm.getStudentbean(), StudentEntity.class);
studentservice.saveStudentForm(studententity);
}catch(Exception e){
e.printStackTrace();
}
return new ModelAndView("abc/helo.html");
}
You are passing StudentModel
class to Dozer, but in your mapping, you are using StudentRequestForm
. 您正在将StudentModel
类传递给Dozer,但在您的映射中,您正在使用StudentRequestForm
。 So, either do this 所以,要么这样做
StudentEntity studententity = mapper.map(studentForm, StudentEntity.class);
OR 要么
<class-a>com.myschool.entity.StudentModel</class-a>
<class-b>com.myschool.entity.StudentEntity</class-b>
<field>
<a>classI</a>
<b>classId</b>
</field>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.