Java树的创建.docx
- 文档编号:10854398
- 上传时间:2023-02-23
- 格式:DOCX
- 页数:22
- 大小:21.74KB
Java树的创建.docx
《Java树的创建.docx》由会员分享,可在线阅读,更多相关《Java树的创建.docx(22页珍藏版)》请在冰豆网上搜索。
Java树的创建
1、所用技术
Java、struts2、ibatis、json、jquery
2、树的查询
--用来的到树的sql-->
selectt.iddeptNo,t.namedeptName
fromt_res_classtwheret.type='0'
fromt_res_deptstwheretype='01'andflag='00'andt.parent=#deptid#
[CDATA[
orderbysnasc
]]>
3、树的action
@SuppressWarnings("serial")
@Component("partsTreeAction")
@Scope("prototype")
publicclassPartsTreeActionextendsActionSupport{
@Autowired
@Qualifier("sqlMapClient")
privateSqlMapClientsqlmapclient;
privateStringid;
publicStringgetId(){
returnid;
}
publicvoidsetId(Stringid){
this.id=id;
}
/**
*一级一级的获得部门树,包括处室
*@return
*@throwsException
*/
publicStringinitTree()throwsException{
commonPart(CommonFunc.getTree_02(id,sqlmapclient));
returnnull;
}
privatevoidcommonPart(Stringmethod)throwsException{
//一级一级的获得部门树
HttpServletResponseresponse=ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
response.setHeader("Cache-Control","no-cache");
PrintWriterout=response.getWriter();
out.print(method);
out.close();
}
}
4、公共方法
publicclassCommonFunc{
/**
*通过部门编号取部门树,为部门管理服务,树只取到部门,处室不取
*
*@paramdeptId
*@return
*/
@SuppressWarnings("unchecked")
publicstaticStringgetTree_02(StringdeptId,SqlMapClientsqlClient){
HashMap
map.put("deptid",deptId);
List
try{
deptList=sqlClient.queryForList("tree_02_select02",map);
}catch(Exceptione){
e.printStackTrace();
}
JSONArraydeptArray=newJSONArray();
for(DepartEntitypart:
deptList){
if(part!
=null){
JSONObjectobj=newJSONObject();
obj.put("id",part.getDeptNo());
obj.put("text",part.getDeptName());
obj.put("state","closed");
deptArray.add(obj);
}
}
returndeptArray.toJSONString();
}
}
5、树的action配置
--展开部门节点-->
--列出部门信息-->
6、dao配置
publicclassP4_02_TreePartsDAO{
/**
*根据部门id查询下属部门信息
*/
@SuppressWarnings({"unchecked"})
publicStringgetPartsById(TreeFormform,SqlMapClientsqlMapClient)
throwsException{
TreeFormsubForm=(TreeForm)form;
StringdeptNo=subForm.getDeptNo();
Mapparams=newHashMap();
params.put("deptNo",deptNo);
//执行按部门id查询
TResDeptsdept1=(TResDepts)sqlMapClient.queryForObject("selectDeptsById",subForm.getDeptNo());
//根据父ID查询其直接下属部门
List
//根据父ID查询其所有直接下属部门
List
List
MapparamMap=newHashMap();
//当dept1等于空的时候,说明id在TResClass表中
if(dept1==null){
//根据父ID查询其直接下属部门
deptsList1=(List
if(deptsList1.size()!
=0){
for(TResDeptsd1:
deptsList1){
//根据父ID查询其所有直接下属部门
deptsList2=(List
if(deptsList2.size()!
=0){
for(TResDeptsd2:
deptsList2){
if(d2!
=null){
partIds.add(d2.getId());
}
}
}
}
}
partIds.add(subForm.getDeptNo());
}else{
//根据父ID查询其所有直接下属部门
deptsList1=(List
if(deptsList1.size()>=0){
for(TResDeptsd:
deptsList1){
partIds.add(d.getId());
}
}
//除去自身部门
partIds.remove(subForm.getDeptNo());
}
if(partIds.size()==0){
//添加伪部门id
partIds.add("999999999999999999999999999999999999999");
}
paramMap.put("partIds",partIds);
//查询的部门列表
List
//部门id数量
intc1=partIds.size();
//查询出的部门记录数量
intc2=Integer.parseInt((String)sqlMapClient.queryForObject("searchDeptByIdCount",paramMap));
if(c1!
=0&&c2!
=0){
subForm.setRowCount(String.valueOf(c2));
deptList=sqlMapClient.queryForList("searchDeptById",paramMap,subForm.getStartRowNum(),subForm.getPageSize());
}
JSONArrayarry=newJSONArray();
JSONObjectp1=newJSONObject();
p1.put("pageCount",subForm.getPageCount());
p1.put("pageNum",subForm.getPageNum());
arry.add(p1);
if(deptList!
=null){
for(TResDeptsd:
deptList){
if(d!
=null){
JSONObjectobj=newJSONObject();
obj.put("deptNo",d.getId());
obj.put("deptName",d.getName());
Stringoptions1=" +d.getId()+"')>详细"; Stringoptions2="/ +d.getId()+"')>订阅设置"; obj.put("options",options1+options2); arry.add(obj); } } } HttpServletResponseresponse=ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); response.setHeader("Cache-Control","no-cache"); PrintWriterout=response.getWriter(); out.print(arry.toJSONString()); out.close(); returnnull; } 7、查询action @SuppressWarnings("serial") @Component("p4_02_Tree_PartsTable_Action") @Scope("prototype") publicclassP4_02_Tree_PartsTable_ActionextendsActionSupport{ privateTreeFormform; @Autowired @Qualifier("sqlMapClient") privateSqlMapClientsqlMapClient; /** *根据部门的id进行查询 *@return *@throwsException */ publicStringinit()throwsException{ form=form==null? newTreeForm(): form; if(StringUtil.isEmpty(form.getDeptNo())){ return"default"; } P4_02_TreePartsDAOdao=newP4_02_TreePartsDAO(); dao.getPartsById(form,sqlMapClient); returnnull; } 8、树的form publicclassTreeFormextendsSplitPageForm{ privateStringdeptNo; //查询的条件,姓名,openid privateStringrealName; privateStringopenid; //查询标志位 privateStringqueryFlag; //部门名称 privateStringname; publicvoidsetDeptNo(StringdeptNo){ this.deptNo=deptNo; } publicStringgetRealName(){ returnrealName; } publicvoidsetRealName(StringrealName){ this.realName=realName; } publicStringgetOpenid(){ returnopenid; } publicvoidsetOpenid(Stringopenid){ this.openid=openid; } publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } publicStringgetQueryFlag(){ returnqueryFlag; } publicvoidsetQueryFlag(StringqueryFlag){ this.queryFlag=queryFlag; } publicStringgetDeptNo(){ returndeptNo; } } 9、分页form /* *分页form,分页页面,在form中需要继承此类 * *@authorzhang_tiecheng */ publicclassSplitPageForm{ /* *当前页号 */ privateStringpageNum=null; /* *每页显示条数 */ privateStringpageSize="15"; /* *总记录数 */ privateStringrowCount=null; publicintgetPageCount(){ intpageCount=(getRowCount()+getPageSize()-1)/getPageSize(); if(pageCount==0){pageCount=1;} returnpageCount; } publicintgetPageNum(){ if(pageNum==null){ pageNum="1"; } returnInteger.valueOf(pageNum); } publicvoidsetPageNum(StringpageNum){ this.pageNum=pageNum; } publicintgetPageSize(){ if(pageSize==null){ pageSize="15"; } returnInteger.valueOf(pageSize); } publicintgetRowCount(){ if(rowCount==null){ rowCount="0"; } returnInteger.valueOf(rowCount); } publicvoidsetRowCount(StringrowCount){ this.rowCount=rowCount; } publicintgetStartRowNum(){ return(getPageNum()-1)*getPageSize(); } } 10、jsp页面 <%@pagecontentType="text/html;charset=utf-8"%> <%@pageimport="java.util.List"%> <%@taglibprefix="s"uri="/struts-tags"%> DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> //www.w3.org/1999/xhtml"> src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"> type="text/css"rel="stylesheet"/> href="${pageContext.request.contextPath}/js/jquery-easyui-1.2/themes/default/easyui.css"/> href="${pageContext.request.contextPath}/js/jquery-easyui-1.2/themes/icon.css"/> src="${pageContext.request.contextPath}/js/jquery-easyui-1.2/jquery.easyui.min.js"> functionsubmit(id){ window.location.href="p4_02_01_01.do? id="+id; } functiondetail(id){ window.location.href="p4_02_01_02.do? form.id="+id; } window.onload=function(){ //if(back="11"){ this.searchTable("11") //} }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 创建
![提示](https://static.bdocx.com/images/bang_tan.gif)