基于Struts2的全局类型转换器
文章目录
LoginAction.java
public class LoginAction implements Action {
//使用类型转换器将字符串请求参数直接转换成一个User实例
private User user;
private User customer;
private Date birth;
//封装Action处理结果的tip属性
private String tip;
public void setUser(User user) {
this.user = user;
}
public void setCustomer(User customer) {
this.customer = customer;
}
public void setTip(String tip) {
this.tip = tip;
}
public void setBirth(Date d) {
this.birth = d;
}
public User getUser() {
return (this.user);
}
public User getCustomer() {
return (this.customer);
}
public Date getBirth() {
return this.birth;
}
public String getTip() {
return (this.tip);
}
public String execute() throws Exception {
if (getUser().getName().equals("admin")
&& getUser().getPass().equals("admin")) {
setTip("转换成功");
return SUCCESS;
} else {
setTip("转换失败");
return ERROR;
}
}
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论