admin 管理员组文章数量: 887021
2023年12月23日发(作者:恢复oracle数据库)
Struts2增删改查例子
UserBean
//要添加set,get
public class UserBean {
private Long id;
private String name;
private String password;
private int age;
private Date birthday;
private Long sex;
private Set
private String des;//描述
}
public class LikeBean {
private Long id;
private String name;
}
FormAction
public class FormAction{
//属性要生成get,set
//标记(添加,修改)
private String tip;
private UserBean userBean;
private List
private List
//到列表页面
public String list(){
userList = new ArrayList
(new UserBean("abc",19,new Date()));
(new UserBean("def",70,new Date()));
(new UserBean("ghi",40,new Date()));
return "list";
}
//到添加页面
public String toAdd(){
likeList = new ArrayList
(new LikeBean(new Long(1),"上网"));
(new LikeBean(new Long(2),"读书"));
(new LikeBean(new Long(3),"游戏"));
tip = "add";
return "info";
}
//添加方法,Struts2会自动把对应的值赋值给userBean
public String add(){
n(userBean);
return "toList";
}
//到更新页面,取出值,设置标记
public String toUpdate(){
likeList = new ArrayList
(new LikeBean(new Long(1),"上网"));
(new LikeBean(new Long(2),"读书"));
(new LikeBean(new Long(3),"游戏"));
tip = "update";
n("update name:"+e());
userBean = new UserBean("update",100,new Date());
(new Long(101));
(new Long(2));
("Struts2用户");
Set
(new Long(2));
(new Long(3));
es(likes);
return "info";
}
//更新方法
public String update(){
n(userBean);
return "toList";
}
//删除方法
public String delete(){
n("del name:"+e());
return "toList";
}
}
配置
method="{1}"> userAction_list ${} ${}
jsp页面
(列表页面)
<%@ taglib prefix="s" uri="/struts-tags" %>
status="st"> href="${tPath}/form/userAction_?use =${}">修改 href="${tPath}/form/userAction_?=${}">删除
(添加和修改页面)
<%@ taglib prefix="s" uri="/struts-tags" %>
format="yyyy-MM-dd" />
rows="8">
listKey="id" listValue="name" label="爱好">
method="%{tip}">
版权声明:本文标题:Struts2简单示例 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1703304313h446180.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论