package cn.itcast.oa.view.action;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.itcast.oa.base.BaseAction;
import cn.itcast.oa.domain.Department;
import cn.itcast.oa.domain.Role;
import cn.itcast.oa.domain.User;
import cn.itcast.oa.util.DepartmentUtils;
import cn.itcast.oa.util.QueryHelper;
import com.opensymphony.xwork2.ActionContext;
@Controller
@Scope("prototype")
public class UserAction extends BaseAction<User> {
private Long departmentId;
private Long[] roleIds;
/** 列表 */
public String list() throws Exception {
// List<User> userList = userService.findAll();
// ActionContext.getContext().put("userList", userList);
// 准备分页信息
new QueryHelper(User.class, "u").preparePageBean(userService, pageNum, pageSize);
return "list";
}
/** 删除 */
public String delete() throws Exception {
userService.delete(model.getId());
return "toList";
}
/** 添加页面 */
public String addUI() throws Exception {
// 准备数据, departmentList
List<Department> topList = departmentService.findTopList();
List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
ActionContext.getContext().put("departmentList", departmentList);
// 准备数据, roleList
List<Role> roleList = roleService.findAll();
ActionContext.getContext().put("roleList", roleList);
return "saveUI";
}
/** 添加 */
public String add() throws Exception {
// 封装到对象中(当model是实体类型时,也可以使用model,但要设置未封装的属性)
// >> 设置所属部门
model.setDepartment(departmentService.getById(departmentId));
// >> 设置关联的岗位
List<Role> roleList = roleService.getByIds(roleIds);
model.setRoles(new HashSet<Role>(roleList));
// >> 设置默认密码为1234(要使用MD5摘要)
String md5Digest = DigestUtils.md5Hex("1234");
model.setPassword(md5Digest);
// 保存到数据库
userService.save(model);
return "toList";
}
/** 修改页面 */
public String editUI() throws Exception {
// 准备数据, departmentList
List<Department> topList = departmentService.findTopList();
List<Department> departmentList = DepartmentUtils.getAllDepartments(topList);
ActionContext.getContext().put("departmentList", departmentList);
// 准备数据, roleList
List<Role> roleList = roleService.findAll();
ActionContext.getContext().put("roleList", roleList);
// 准备回显的数据
User user = userService.getById(model.getId());
ActionContext.getContext().getValueStack().push(user);
if (user.getDepartment() != null) {
departmentId = user.getDepartment().getId();
}
if (user.getRoles() != null) {
roleIds = new Long[user.getRoles().size()];
int index = 0;
for (Role role : user.getRoles()) {
roleIds[index++] = role.getId();
}
}
return "saveUI";
}
/** 修改 */
public String edit() throws Exception {
// 1,从数据库中取出原对象
User user = userService.getById(model.getId());
// 2,设置要修改的属性
user.setLoginName(model.getLoginName());
user.setName(model.getName());
user.setGender(model.getGender());
user.setPhoneNumber(model.getPhoneNumber());
user.setEmail(model.getEmail());
user.setDescription(model.getDescription());
// >> 设置所属部门
user.setDepartment(departmentService.getById(departmentId));
// >> 设置关联的岗位
List<Role> roleList = roleService.getByIds(roleIds);
user.setRoles(new HashSet<Role>(roleList));
// 3,更新到数据库
userService.update(user);
return "toList";
}
/** 初始化密码为1234 */
public String initPassword() throws Exception {
// 1,从数据库中取出原对象
User user = userService.getById(model.getId());
// 2,设置要修改的属性(要使用MD5摘要)
String md5Digest = DigestUtils.md5Hex("1234");
user.setPassword(md5Digest);
// 3,更新到数据库
userService.update(user);
return "toList";
}
/** 登录页面 */
public String loginUI() throws Exception {
return "loginUI";
}
/** 登录 */
public String login() throws Exception {
User user = userService.findByLoginNameAndPassword(model.getLoginName(), model.getPassword());
if (user == null) {
addFieldError("login", "用户名或密码不正确!");
return "loginUI";
} else {
// 登录用户
ActionContext.getContext().getSession().put("user", user);
return "toIndex";
}
}
/** 注销 */
public String logout() throws Exception {
ActionContext.getContext().getSession().remove("user");
return "logout";
}
// ---
public Long getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Long departmentId) {
this.departmentId = departmentId;
}
public Long[] getRoleIds() {
return roleIds;
}
public void setRoleIds(Long[] roleIds) {
this.roleIds = roleIds;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JAVA-人事管理系统项目.zip
共1320个文件
gif:739个
js:193个
png:53个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 53 浏览量
2023-03-29
18:23:39
上传
评论
收藏 48.76MB ZIP 举报
温馨提示
JAVA_人事管理系统项目.zip
资源推荐
资源详情
资源评论
收起资源包目录
JAVA-人事管理系统项目.zip (1320个子文件)
config.ascx 5KB
class_upload.asp 10KB
io.asp 7KB
commands.asp 6KB
config.asp 6KB
connector.asp 2KB
upload.asp 2KB
basexml.asp 2KB
util.asp 1KB
connector.aspx 1KB
upload.aspx 1KB
image.cfc 46KB
ImageObject.cfc 12KB
cf5_upload.cfm 11KB
cf5_connector.cfm 10KB
cf_io.cfm 10KB
cf_commands.cfm 8KB
config.cfm 8KB
spellchecker.cfm 5KB
cf_util.cfm 4KB
cf_connector.cfm 3KB
cf_basexml.cfm 3KB
cf_upload.cfm 2KB
connector.cfm 1005B
upload.cfm 993B
connector.cgi 4KB
upload.cgi 3KB
UserAction.class 6KB
DaoSupportImpl.class 5KB
User.class 4KB
AnchorTag.class 4KB
TreeViewPractice.class 4KB
RoleAction.class 4KB
Installer.class 3KB
QueryHelper.class 3KB
DepartmentAction.class 3KB
ForumAction.class 3KB
TopicAction.class 3KB
TopicServiceImpl.class 3KB
ReplyServiceImpl.class 3KB
BaseAction.class 3KB
ForumServiceImpl.class 3KB
ForumManageAction.class 3KB
Forum.class 2KB
Privilege.class 2KB
ReplyAction.class 2KB
Department.class 2KB
Topic.class 2KB
DepartmentUtils.class 2KB
DepartmentServiceImpl.class 2KB
InitListener.class 2KB
PageBean.class 2KB
Role.class 2KB
QueryHelperTest.class 2KB
CheckPrivilegeInterceptor.class 2KB
Article.class 2KB
SpringTest.class 1KB
UserServiceImpl.class 1KB
TestService.class 1KB
PrivilegeServiceImpl.class 1KB
LogTest.class 1KB
TestAction.class 982B
HomeAction.class 949B
DaoSupport.class 924B
RoleServiceImpl.class 645B
DepartmentDaoImpl.class 631B
BaseDaoTest.class 631B
ReplyService.class 612B
TopicService.class 612B
DepartmentService.class 599B
Reply.class 571B
RoleDaoImpl.class 547B
PrivilegeService.class 491B
UserDaoImpl.class 461B
UserService.class 363B
DepartmentDao.class 349B
UserDao.class 331B
RoleDao.class 331B
ForumService.class 320B
RoleService.class 259B
pageCommon.css 17KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_dialog.css 6KB
fck_dialog.css 6KB
fck_dialog.css 6KB
fck_internal.css 4KB
forum.css 4KB
top.css 4KB
file.css 4KB
fck_editorarea.css 3KB
jquery.treeview.css 3KB
style.css 2KB
selectPerson.css 2KB
menu.css 2KB
login.css 2KB
fck_dialog_common.css 2KB
fck_showtableborders_gecko.css 2KB
browser.css 2KB
共 1320 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
程序员一灯
- 粉丝: 835
- 资源: 2134
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功