Spring MVC 3<形式 :选择>标签多选

发布于 2024-12-07 15:18:00 字数 1927 浏览 0 评论 0原文

我需要在多重选择表单中选择多个值:选择标签。我的jsp代码是

<form:form id="myForm"
action="service.do" modelAttribute="services"
method="POST">
 ....
 ....

<form:select path="channelsInvolved" items="${allChannels}" itemValue="channelid" itemLabel="channelname"> 

我的控制器是...

List<Channels> channels = dao.getAllChannels();
model.addAttribute("allChannels", channels);

ServiceRegistration serRegistration = dao.getById(2);
model.put("services", serRegistration);

实际上,我有3个表-> ServiceRegistration、Channels(包含 META 数据)和 ServiceChannel。 ServiceChannel 包含服务注册和通道表的外键引用。因此,一个serviceid可以在servicechannel表中映射多个channelid。

我的 ServiceRegistration.java 实体类具有 ChannelsInvolved 字段作为...

@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER)
 @JoinTable(name = "ServiceChannel", joinColumns = {
 @JoinColumn(name="serviceid", unique = true) 
 },
 inverseJoinColumns = {
 @JoinColumn(name="channelid")
 }
 )

 private List<Channels> channelsInvolved;

     public List<Channels> getChannelsInvolved() {
    return channelsInvolved;
  }

public void setChannelsInvolved(List<Channels> channelsInvolved) {
    this.channelsInvolved = channelsInvolved;
  }

Channel 实体类... Channels.java

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int channelid;
@Column private String channelname; 

ServiceChannel.java 实体类...

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int servicechannelid;    

@ManyToOne
@JoinColumn(name = "serviceid")
private ServiceRegistration serviceRegistration;

@ManyToOne
@JoinColumn(name = "channelid")
private Channels channels;

比如说,我有一个服务 id >>> 2 映射到channelid>> 1和2。我可以在“channelsInvolved”中看到2条记录。但是当我将 serRegistration 设置为 jsp 的模型属性时,选择标记中没有选择任何一个。

帮助表示赞赏,谢谢。

I need to select multiple values in the multiple selection form:select tag. my jsp code is

<form:form id="myForm"
action="service.do" modelAttribute="services"
method="POST">
 ....
 ....

<form:select path="channelsInvolved" items="${allChannels}" itemValue="channelid" itemLabel="channelname"> 

my controller is...

List<Channels> channels = dao.getAllChannels();
model.addAttribute("allChannels", channels);

ServiceRegistration serRegistration = dao.getById(2);
model.put("services", serRegistration);

Actually, I have 3 tables -> ServiceRegistration, Channels (contains META data) and ServiceChannel. ServiceChannel contains foreign key reference with both serviceregistration and channel tables. So, one serviceid may have multiple channelid's mapped in the servicechannel table.

my ServiceRegistration.java entity class has the channelsInvolved field as...

@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.EAGER)
 @JoinTable(name = "ServiceChannel", joinColumns = {
 @JoinColumn(name="serviceid", unique = true) 
 },
 inverseJoinColumns = {
 @JoinColumn(name="channelid")
 }
 )

 private List<Channels> channelsInvolved;

     public List<Channels> getChannelsInvolved() {
    return channelsInvolved;
  }

public void setChannelsInvolved(List<Channels> channelsInvolved) {
    this.channelsInvolved = channelsInvolved;
  }

Channel entity class... Channels.java

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int channelid;
@Column private String channelname; 

ServiceChannel.java entity class...

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column private int servicechannelid;    

@ManyToOne
@JoinColumn(name = "serviceid")
private ServiceRegistration serviceRegistration;

@ManyToOne
@JoinColumn(name = "channelid")
private Channels channels;

Say, I have a service id >> 2 mapped to channelid >> 1 and 2. I am able see 2 records in the "channelsInvolved". But when I set the serRegistration as model attribute to the jsp, none is selected in the select tag.

help appreciated, Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单调的奢华 2024-12-14 15:18:00

您将需要在实体中(尤其是在通道中)正确实现equals

You will need a correct equals implementation in you Entities (especially in Channels).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文