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 likes;

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 likeList;

private List userList;

//到列表页面

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 likes = new HashSet();

(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}">

/form/

/form/

userAction_list

${}

${}

jsp页面

(列表页面)

<%@ taglib prefix="s" uri="/struts-tags" %>

用户列表

status="st">

 

 

 

HH:mm:ss" />    

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}">


本文标签: 添加 方法 参数 对应 设置