我有对象类User.java

@Entity
@Table(name = "UserMst")
public class User implements Serializable{
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long userId;

@Column(name="emailId")
private String emailId;

@Column(name="userName")
private String userName;

@Column(name="address")
private String address;

@Column(name="mobNo")
private BigDecimal mobNo;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "deptId")
private Department department;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "desgId")
private Designation designation;

@Column(name="grpId")
private int grpId ;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumns({
  @JoinColumn(name = "sk"),
  @JoinColumn(name = "pk")})
private Config config ;

@Column(name="upw1")
private String upw1 ;

@Column(name="upw2")
private String upw2 ;

@Column(name="upw3")
private String upw3 ;

@Column(name="createdBy")
private String createdBy ;

@Column(name="creationDate")
private Timestamp creationDate;

@Column(name="loginStatus")
private String loginStatus;

@Column(name="hintId")
private int hintId ;

@Column(name="hintAns")
private String hintAns ;

@Column(name="otp")
private String otp ;


而另一个Object Config.java具有复合键(sk,pk),它是User对象的外键。

 @Entity
 @Table(name = "config")
 public class Config implements Serializable{

  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private String pk;

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private String sk;

  @Column(name="ds")
  private String ds;

  @Column(name="value")
  private String value;


现在我有了Config的列表,并在存在下拉列表的jsp上传递了该列表
并希望将选项值绑定到该复合键(sk,pk)



<select name="userLevel" id="lvl_Id" class="form-control" size="0">
  <option value="-1">--Select--</option>
      <c:forEach var="levelList" items="${levelList}">
      <option value="<c:out value="${levelList.sk}|${levelList.pk}" />">${levelList.ds}</option>
    </c:forEach>
</select>





有人可以帮我吗?

提前致谢。

最佳答案

如果要将复合键传递给控制器​​端,则可以使用html标签将数据传递到隐藏字段中。



可能是您的问题会解决。

关于java - 如何在Spring和Hibernate中将复合键从 Controller 传递到JSP?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51281220/

10-10 07:12