首页新闻找找看学习计划

用s标签怎么做下拉框的层级关系

0
悬赏园豆:100 [已关闭问题] 关闭于 2017-03-18 10:03

最近正在学习s标签,遇到了一个问题

然后我用s标签做的时候回显是可以回显,但是不显示层级关系,s:if不是太会用

<s:select list="#department" name="parentId" 
          listKey="id" listValue="departmentName" 
      headerKey="" headerValue="请选择部门" >

</s:select>

 

 


  用ssh做的
表的字段

public class Department implements Serializable{
    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private Integer id;
    private String departmentName;
    private String description;
    
    //一对多的一端
    private Set<Department> children = new HashSet<Department>();
    private Set<User> users = new HashSet<User>();
    //一对多的多端
    private Department parent;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getDepartmentName() {
        return departmentName;
    }
    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public Set<Department> getChildren() {
        return children;
    }
    public void setChildren(Set<Department> children) {
        this.children = children;
    }
    public Department getParent() {
        return parent;
    }
    public void setParent(Department parent) {
        this.parent = parent;
    }
    public Set<User> getUsers() {
        return users;
    }
    public void setUsers(Set<User> users) {
        this.users = users;
    }
    
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="com.OA.entity">
        <class name="Department" table="t_department">
            <id name="id">
                <generator class="native"/>
            </id>
        <property name="departmentName" column="department_name"/>
        <property name="description" length="500"/>
        
        <!-- 一对多关联 -->
        <set name="children" cascade="delete" inverse="true">
            <key column="parent_id"/>
            <one-to-many class="Department"/>
        </set>
        <!-- 多对一关联 -->
        <many-to-one name="parent" class="Department" column="parent_id"/>
        
        <!-- 部门对用户一对多 -->
        <set name="users" cascade="delete" inverse="true">
            <key column="department_id" />
            <one-to-many class="User"/>
        </set>
        
        </class>
    </hibernate-mapping>

 

 
 


在Action层中

public String saveUI(){
        List<Department> department = departmentService.findAll();
        ActionContext.getContext().put("department",department);
        return "saveUI";
    }

 


求大神帮下忙,判断标签该写在哪里,该怎么写?

问题补充:

好像是用递归写的,不是s:if

//HelloWorld的主页 //HelloWorld | 初学一级 | 园豆:68
提问于:2017-03-18 08:44
< >
分享
所有回答(1)
0

问题已解决,是用递归完成的,我写了一个工具类,大概是这样的

package com.oa.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.bwie.oa.entity.Department;

public class DepartmentUtil {

    
    public static List<Department> getDepartments(List<Department> topList)
    {
        List<Department> list = new ArrayList<Department>();
        walkDepartmentList(topList, "┣", list);
        
        return list ;
    }
    
    private static void walkDepartmentList(Collection<Department> topList , String prefix , List<Department> list)
    {
        for (Department top : topList) {
            
            Department copy = new Department();
            copy.setId(top.getId());
            copy.setDepartmentName(prefix + top.getDepartmentName());
            
            list.add(copy);
            
            
            walkDepartmentList(top.getChildren() , "  " + prefix , list );//半角空格 不可以  需要用 全角空格
        }
        
    }
}
希望对大家有所帮助
//HelloWorld | 园豆:68 (初学一级) | 2017-03-18 10:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册