struts.xml 这是 Struts 类请告诉我使用strut2 hibernate JPA 更新的正确方法关于按 id 更新<struts><package name="com.Attendance" extends="struts-default"> <action name="RegTeacher" class="com.Attendance.TeacherAction" > <result name="success">/Admin/success.jsp</result> <result name="error">/Admin/RegistrationTeacher.jsp</result> <result name="input">/Admin/RegistrationTeacher.jsp</result> </action> <action name="EditTeacher" class="com.Attendance.TeacherAction" method="FindById"> <result name="success">/Admin/UDTeacher.jsp</result> <result name="input">/Admin/ShowAllTeacher.jsp</result> </action> <action name="UDTeacher" class="com.Attendance.TeacherAction" method="Update"> <result name="success">/Admin/success.jsp</result> <result name="error">/Admin/UDTeacher.jsp</result> <result name="input">/Admin/UDTeacher.jsp</result> </action> </package> <constant name="struts.action.excludePattern" value="/CheckCode,/CheckRegistrationAdmin," /> </struts>`RegTeacher 这是模型/实体类请告诉我用strut2 hibernate JPA更新的正确方法关于按id更新 ` package com.Attendance; import javax.persistence.*; @Entity @Table(name="Teacher") public class RegTeacher{ @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name = "id", nullable = false) private int id; @Column(name = "LecturerName",unique=true,nullable=false) private String Name; @Column(name= "email",unique=true,nullable=false) private String email; @Column(name= "pass",nullable=false) private String Password; @Column(name="Course",nullable=false) private String CourseT; @Column(name= "ClassName",nullable=false) private String CName; /** setter and getter **/ }`TecaherAction 这是 Action 类
1 回答
BIG阳
TA贡献1859条经验 获得超6个赞
从错误中可以清楚地看出Duplicate entry 'Rajan' for key 'LecturerName'
,您尝试的实体Update
被视为重复。原因是每次都调用execute
方法来保存实体而不是更新它。TeacherAction
您的问题的解决方案是调用动作类的特定(特定于 jsp 页面)方法。尝试在UpdateTeacher.jsp中添加以下代码行
<s:form action="RegTeacher" method="Update" theme="simple" >
提示:我建议遵循编码标准,使每个人都可以轻松跟踪和理解代码。
添加回答
举报
0/150
提交
取消