gpt4 book ai didi

java - Struts2 中的日期转换

转载 作者:行者123 更新时间:2023-11-29 10:14:53 25 4
gpt4 key购买 nike

<分区>

我想知道如何在 Struts2 中将 String 转换为 Date。我有一个简单的表单,用户可以在其中以 "yyyy-MM-dd" 格式提供日期。将 Sturts2 映射表提交给 bean。我在日期转换时出错。我谷歌了很多,每一个地方都说我们必须为此使用自定义类型转换器。我不想为日期转换编写自定义类型转换器。我认为在 Struts2 中应该有一个简单的数据转换机制,因为数据转换是非常常见的功能。

JSP

<s:form action="AddDomain">
<s:push value="idp">
<s:textfield name="domainName" label="Domain Name" />
<s:textfield name="url" label="Domain URL" />
<s:textfield name="noOfLicense" label="License Purchased" />

<s:textfield name="licenseExpireDate" label="License Expire Date"
title="YYYY-MM-DD like 2013-01-21" />

<s:textfield name="userActiveDuration" label="Active User Duration"
title="please mention in days" />

<s:textarea name="notes" label="Note" cols="30" rows="5" ></s:textarea>

<s:submit value="Add" />
</s:push>
</s:form>

这是用户输入内容的 JSP。

模型类

@Entity
@Table(name = "Domain")
public class IdentityProvider implements Serializable {

@Id
@Basic(optional = false)
private String url;
private String domainName;
private int noOfLicense;
private int userActiveDuration;
private int activeUsers;
private Date licenseExpireDate;
private String notes;

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

public IdentityProvider(String name, String url, int nol, int time,Date d,String notes) {
this.setDomainName(name);
this.setUrl(url);
this.setNoOfLicense(nol);
this.setUserActiveDuration(time);
this.setLicenseExpireDate(d);
this.setNotes(notes);
}

public IdentityProvider() {

}

// Getter Setter
}

Action 类

public class DomainManagementAction extends ActionSupport 
implements ModelDriven<IdentityProvider> {

private IdentityProvider idp = new IdentityProvider();

public IdentityProvider getIdp() {
return idp;
}

public void setIdp(IdentityProvider idp) {
this.idp = idp;
}

public String saveDomain() {
IDPBroker broker = new IDPBroker();
broker.saveDomain(idp);
return ActionSupport.SUCCESS;
}


@Override
public IdentityProvider getModel() {
// TODO Auto-generated method stub
return idp;
}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com