📄 useraction.java
字号:
package com.zhongrx.struts2.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.zhongrx.pojo.User;
import com.zhongrx.service.UserService;
public class UserAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String password;
private List users;
private UserService userService;
public void setUserService(UserService userService) {
this.userService = userService;
}
public String list() throws Exception {
List result = userService.findAllWithSorting(User.class, "id", true);
setUsers(result);
return SUCCESS;
}
public String save() throws Exception {
User user = new User();
user.setUsername(this.getUsername());
user.setPassword(this.getPassword());
userService.save(user);
return SUCCESS;
}
public String edit() throws Exception {
User user = (User)userService.load(User.class, this.getId());
this.setUsername(user.getUsername());
this.setPassword(user.getPassword());
return SUCCESS;
}
public String update() throws Exception {
User user = (User)userService.load(User.class, this.getId());
user.setUsername(this.getUsername());
user.setPassword(this.getPassword());
userService.update(user);
return SUCCESS;
}
public String delete() throws Exception {
userService.delete((User)userService.load(User.class, this.getId()));
return SUCCESS;
}
public List getUsers() {
return users;
}
public void setUsers(List users) {
this.users = users;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -