1 岗位实体
package cn.itcast.oa.domain;
import java.util.HashSet;
import java.util.Set;
/**
* 岗位实体
*/
public class Role {
private Long id;
private String name;
private String description;
private Set<User> users = new HashSet<User>();
private Set<Privilege> privileges = new HashSet<Privilege>();
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<User> getUsers() {
return users;
}
public void setUsers(Set<User> users) {
this.users = users;
}
public void setPrivileges(Set<Privilege> privileges) {
this.privileges = privileges;
}
public Set<Privilege> getPrivileges() {
return privileges;
}
}
2 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cn.itcast.oa.domain.Role" table="itcast_role">
<id name="id">
<generator class="native"/>
</id>
<property name="name" length="32"/>
<property name="description" length="128"/>
<!-- 岗位和用户的多对多关系 -->
<set name="users" table="itcast_user_role">
<key column="roleId"/>
<many-to-many class="cn.itcast.oa.domain.User" column="userId"/>
</set>
<!-- 角色和权限的多对多关系 -->
<set name="privileges" table="itcast_role_privilege" lazy="false">
<key column="roleId"/>
<many-to-many class="cn.itcast.oa.domain.Privilege" column="privilegeId"/>
</set>
</class>
</hibernate-mapping>
3public interface IRoleDao extends IBaseDao<Role> {
}
4
package cn.itcast.oa.dao.impl;
import org.springframework.stereotype.Repository;
import cn.itcast.oa.base.BaseDaoImpl; import cn.itcast.oa.dao.IRoleDao; import cn.itcast.oa.domain.Role;
@Repository public class RoleDaoImpl extends BaseDaoImpl<Role> implements IRoleDao { }
5
public interface IRoleService {
public List<Role> findAll();
public void delete(Role model);
public Role getById(Long id);
public void update(Role role);
public void save(Role model);
public List<Role> getByIds(Long[] roleIds);
}
6
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;
import cn.itcast.oa.dao.IRoleDao; import cn.itcast.oa.domain.Role; import cn.itcast.oa.service.IRoleService;
/** * 宀椾綅绠$悊 * @author zhaoqx * */ @Service @Transactional public class RoleServiceImpl implements IRoleService { @Resource private IRoleDao roleDao;
public List<Role> findAll() { return roleDao.findAll(); }
public void delete(Role model) { roleDao.delete(model.getId()); }
public Role getById(Long id) { return roleDao.getById(id); }
public void update(Role role) { roleDao.update(role); }
public void save(Role model) { roleDao.save(model); }
public List<Role> getByIds(Long[] roleIds) { return roleDao.getByIds(roleIds); }
}
7 首先是role list.jsp
进入xml
<action name="role_*" class="roleAction" method="{1}">
* 查询岗位列表
*/
public String list(){
List<Role> list = roleService.findAll();
ValueStack vs = getValueStack();
vs.set("list", list);
return "list";
}
<result name="list">/WEB-INF/jsp/role/list.jsp</result>
<s:iterator value="list">
<tr class="TableDetail1 template">
<td>${name} </td>
<td>${description} </td>
<td><s:a onclick="return window.confirm('确定删除当前记录吗?')" action="role_delete?id=%{ id }" namespace="/">删除</s:a>
<s:a action="role_editUI?id=%{ id }" namespace="/">修改</s:a>
<s:a action="role_setPrivilegeUI?id=%{id}" namespace="/">设置权限</s:a>
</td>
</tr>
</s:iterator>