├── MySqlJDBC.java ├── Neo4jRestAPI.java ├── addClassUserInfo.jsp ├── admin └── AdminInfo.java ├── controller ├── AddClassUserInfoServlet.java ├── AddNodeController1.java ├── AddNodeController2.java ├── DisplayController.java ├── LoginServlet.java └── UserInfoServlet.java ├── framework.jsp ├── index.jsp ├── inputInfo.jsp ├── login.jsp ├── model ├── BookBeanDBA.java ├── ClassBeanDBA.java ├── FacultyBeanDBA.java ├── GradeBeanDBA.java ├── MajorBeanDBA.java ├── UserBeanDBA.java ├── UserClassBeanDBA.java └── UserInfoConfigBeanDBA.java ├── model2 ├── NodeBeanDBA.java └── RelationshipBeanDBA.java ├── preparations ├── GetNodes.java ├── GetPaths.java ├── JsonFormat.java ├── displayInWeb.html ├── increaseAndDecrease.html └── myStyle.css ├── showUserInfoConfig.jsp └── systemInfo └── SystemInfo.java /MySqlJDBC.java: -------------------------------------------------------------------------------- 1 | package com.zehua; 2 | 3 | import java.sql.*; 4 | import java.util.ArrayList; 5 | 6 | public class MysqlJDBC { 7 | static Connection conn = null; 8 | static PreparedStatement preparedStatement = null; 9 | static ResultSet resultSet = null; 10 | 11 | //得到connection 12 | public static Connection getConn(){ 13 | String driver = "com.mysql.jdbc.Driver"; 14 | String url = "jdbc:mysql://127.0.0.1:3306/dbcd?useUnicode=true&characterEncoding=utf-8&useSSL=false"; 15 | String user = "scott"; 16 | String password = "tiger"; 17 | try { 18 | Class.forName(driver); 19 | conn = DriverManager.getConnection(url,user,password); 20 | } catch (ClassNotFoundException e) { 21 | e.printStackTrace(); 22 | } catch (SQLException e) { 23 | e.printStackTrace(); 24 | } 25 | return conn; 26 | } 27 | //关闭连接 28 | public static void close(Connection conn,PreparedStatement preparedStatement,ResultSet resultSet){ 29 | if (conn!=null){ 30 | try { 31 | conn.close(); 32 | } catch (SQLException e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | if (preparedStatement!=null){ 37 | try { 38 | preparedStatement.close(); 39 | } catch (SQLException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | if (resultSet!=null){ 44 | try { 45 | resultSet.close(); 46 | } catch (SQLException e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | } 51 | //查询,返回查询集 52 | public static ArrayList[] query(String sql, String[] parameters){ 53 | ArrayList[] resultArray = null; 54 | getConn(); 55 | try { 56 | preparedStatement = conn.prepareStatement(sql); 57 | if(parameters!=null){ 58 | for(int i = 0;i arrays = new ArrayList<>(); 69 | 70 | int arrayLength = 0; 71 | int rowCount = 0;//为了得到记录的行数 72 | while(resultSet.next()){//每次移动一条数据 73 | rowCount++; 74 | ArrayList array = new ArrayList(); 75 | for(int index = 1;index<=colsCount;index++){ 76 | //对于每一条记录,分别得到每列的数据 77 | String str = resultSet.getString(index); 78 | array.add(str); 79 | } 80 | arrays.add(array); 81 | } 82 | //当过了循环体后,就可以的到记录的数目了; 83 | resultArray = new ArrayList[rowCount]; 84 | for(int i = 0;i executeFindNodeCypher(String cypher){ 41 | getDriver(); 42 | 43 | Map node_AttrKey_AttrValue_Map = new HashMap<>(); 44 | 45 | try(Session session = driver.session()){ 46 | StatementResult result = session.run(cypher); 47 | 48 | while(result.hasNext()){ 49 | Record record = result.next(); 50 | List value = record.values(); 51 | 52 | for(Value i:value){ 53 | Node node = i.asNode(); 54 | Iterator keys = node.keys().iterator(); 55 | 56 | while(keys.hasNext()){ 57 | String attrKey = (String)keys.next(); 58 | String attrValue = node.get(attrKey).asString(); 59 | node_AttrKey_AttrValue_Map.put(attrKey,attrValue); 60 | } 61 | } 62 | } 63 | } 64 | close(); 65 | return node_AttrKey_AttrValue_Map; 66 | } 67 | //relation 68 | public static Map executeFindRelAttrCypher(String cypher){ 69 | getDriver(); 70 | 71 | Map Rel_AttrKey_AttrValue_Map = new HashMap<>(); 72 | 73 | try(Session session = driver.session()){ 74 | StatementResult result = session.run(cypher); 75 | 76 | while(result.hasNext()){ 77 | Record record = result.next(); 78 | List value = record.values(); 79 | 80 | for(Value i:value){ 81 | Map map = i.asMap(); 82 | Rel_AttrKey_AttrValue_Map = map; 83 | } 84 | } 85 | } 86 | close(); 87 | return Rel_AttrKey_AttrValue_Map; 88 | } 89 | //返回关系的StringBuffer,为可视化做准备!json文件 90 | public static StringBuffer executeFindRelationCypher(String cypher){ 91 | //关系的StringBuffer,json格式 92 | StringBuffer relationBuffer = new StringBuffer(""); 93 | relationBuffer.append("\"links\":[");//return "links":[ 94 | getDriver(); 95 | 96 | try(Session session = driver.session()){ 97 | //result包含了所有的path 98 | StatementResult result = session.run(cypher); 99 | 100 | while(result.hasNext()){ 101 | Record record = result.next(); 102 | List value = record.values(); 103 | 104 | for(Value i:value){ 105 | Path path = i.asPath(); 106 | Iterator relationships = path.relationships().iterator(); 107 | 108 | while(relationships.hasNext()){ 109 | Relationship relationship = relationships.next(); 110 | 111 | long startNodeId = relationship.startNodeId(); 112 | long endNodeId = relationship.endNodeId(); 113 | String relType = relationship.type(); 114 | 115 | //得到关系属性的健 116 | Iterator relKeys = relationship.keys().iterator(); 117 | 118 | relationBuffer.append("{"); 119 | relationBuffer.append("\"source\":"); 120 | relationBuffer.append(startNodeId); 121 | relationBuffer.append(","); 122 | relationBuffer.append("\"target\":"); 123 | relationBuffer.append(endNodeId); 124 | relationBuffer.append(","); 125 | relationBuffer.append("\"type\":"); 126 | relationBuffer.append("\""+relType+"\""); 127 | 128 | //这里处理关系属性 129 | while(relKeys.hasNext()){ 130 | String relKey = relKeys.next(); 131 | String relValue = relationship.get(relKey).asObject().toString(); 132 | 133 | //去除制表符 134 | relValue = relValue.replaceAll("\t",""); 135 | //去除换行符 136 | relValue= relValue.replaceAll("\r",""); 137 | //去除回车符 138 | relValue = relValue.replaceAll("\n",""); 139 | 140 | //将双引号换成单引号 141 | relValue = relValue.replaceAll("\"","'"); 142 | 143 | relationBuffer.append(","); 144 | relationBuffer.append("\""+relKey+"\""); 145 | relationBuffer.append(":"); 146 | relationBuffer.append("\""+relValue+"\""); 147 | } 148 | if(!relationships.hasNext()&&!result.hasNext()){ 149 | relationBuffer.append("}"); 150 | } 151 | else { 152 | //如果是最后一个,只需要添加}即可 153 | relationBuffer.append("},"); 154 | } 155 | 156 | } 157 | } 158 | } 159 | } 160 | relationBuffer.append("]"); 161 | close(); 162 | return relationBuffer; 163 | } 164 | //返回关系中节点的StringBuffer,为可视化做准备!json文件,需要增加节点的类型 165 | public static StringBuffer executeFindRelationNodesCypher(String cypher) { 166 | //用一个set集合去除重复项 167 | Set nodeSet = new HashSet(); 168 | StringBuffer relationNodesBuffer = new StringBuffer(""); 169 | relationNodesBuffer.append("\"nodes\":["); 170 | getDriver(); 171 | 172 | try(Session session = driver.session()){ 173 | StatementResult result = session.run(cypher); 174 | 175 | while(result.hasNext()){ 176 | Record record = result.next(); 177 | List value = record.values(); 178 | 179 | for(Value i:value){ 180 | 181 | Path path = i.asPath(); 182 | Iterator nodes = path.nodes().iterator(); 183 | 184 | while(nodes.hasNext()){ 185 | Node node = nodes.next(); 186 | //在增加节点以前,先判断是否在集合中 187 | boolean isExist = nodeSet.contains(node.id()); 188 | if (isExist) continue; 189 | Iterator nodeKeys = node.keys().iterator(); 190 | relationNodesBuffer.append("{"); 191 | 192 | //节点属性 193 | while(nodeKeys.hasNext()){ 194 | String nodeKey = nodeKeys.next(); 195 | relationNodesBuffer.append("\""+nodeKey+"\":"); 196 | //node.get(nodeKey).toString(); 197 | //System.out.println(node.get(nodeKey).asObject().toString()); 198 | String content = node.get(nodeKey).asObject().toString(); 199 | 200 | //去除制表符 201 | content = content.replaceAll("\t",""); 202 | //去除换行符 203 | content = content.replaceAll("\r",""); 204 | //去除回车符 205 | content = content.replaceAll("\n",""); 206 | 207 | //将双引号换成单引号 208 | content = content.replaceAll("\"","'"); 209 | 210 | relationNodesBuffer.append("\""+content+"\","); 211 | } 212 | relationNodesBuffer.append("\"id\":"); 213 | relationNodesBuffer.append(node.id()); 214 | //添加节点类型!不知道为什么取得节点类型用的是labels,可能一个节点可以属于多个类别 215 | //但是我们这里只属于一个类别! 216 | Iterator nodeTypes = node.labels().iterator(); 217 | //得到节点类型了! 218 | String nodeType = nodeTypes.next(); 219 | 220 | relationNodesBuffer.append(","); 221 | relationNodesBuffer.append("\"type\":"); 222 | relationNodesBuffer.append("\""+nodeType+"\""); 223 | 224 | 225 | //从SystemInfo中得到NodeTypeKeys,好为新的节点类型分配颜色 226 | Set nodeTypeKeys = SystemInfo.getNodeTypeKeys(); 227 | 228 | //如果是新的节点类型,则分配颜色,并保持到SystemInfo中 229 | if(!nodeTypeKeys.contains(nodeType)){ 230 | int colorIndex = nodeTypeKeys.size(); 231 | //以防万一,所需颜色超过5,则随机一种颜色 232 | if(colorIndex>=5){ 233 | colorIndex = (int)Math.random()*5; 234 | } 235 | //得到颜色集合 236 | String[] colors = SystemInfo.getColor(); 237 | String color = colors[colorIndex]; 238 | //添加 239 | SystemInfo.addNodeType_Color(nodeType,color); 240 | //添加颜色属性 241 | relationNodesBuffer.append(","); 242 | relationNodesBuffer.append("\"color\":"); 243 | relationNodesBuffer.append("\""+color+"\""); 244 | } 245 | else{ 246 | //说明不是新的节点 247 | //通过nodeType得到该节点的颜色 248 | Map nodeType_Color = SystemInfo.getNodeType_Color(); 249 | String color = nodeType_Color.get(nodeType).toString(); 250 | //添加颜色属性 251 | relationNodesBuffer.append(","); 252 | relationNodesBuffer.append("\"color\":"); 253 | relationNodesBuffer.append("\""+color+"\""); 254 | } 255 | 256 | //将节点添加到set集合中 257 | nodeSet.add(node.id()); 258 | 259 | if(!nodes.hasNext()&&!result.hasNext()){ 260 | relationNodesBuffer.append("}"); 261 | } 262 | else{ 263 | relationNodesBuffer.append("},"); 264 | } 265 | } 266 | } 267 | } 268 | } 269 | int bufferLength = relationNodesBuffer.length(); 270 | char lastChar = relationNodesBuffer.charAt(bufferLength-1); 271 | if(lastChar==','){ 272 | String str = relationNodesBuffer.substring(0,relationNodesBuffer.length()-1); 273 | relationNodesBuffer = relationNodesBuffer.replace(0,bufferLength,str); 274 | } 275 | relationNodesBuffer.append("]"); 276 | close(); 277 | return relationNodesBuffer; 278 | } 279 | //执行多条cypher语句 280 | //处理关系 281 | public static StringBuffer executeFindRelationCyphers(ArrayList cypherArrayList){ 282 | StringBuffer relationBuffer = new StringBuffer(""); 283 | relationBuffer.append("\"links\":[");//return "links":[ 284 | getDriver(); 285 | 286 | int index = 0; 287 | 288 | //新建一个Map,以startNodeId作为key,以endNodeId作为value,用来去重 289 | Map start_end = new HashMap<>(); 290 | 291 | //不知道可不可以批处理 292 | //这里我就没用批处理了 293 | try(Session session = driver.session()){ 294 | 295 | for(int i = 0;i list = record.values(); 302 | 303 | for(Value item:list){ 304 | Path path = item.asPath(); 305 | Iterator rels = path.relationships().iterator(); 306 | while(rels.hasNext()){ 307 | index++; 308 | 309 | Relationship relationship = rels.next(); 310 | long startNodeId = relationship.startNodeId(); 311 | long endNodeId = relationship.endNodeId(); 312 | 313 | //先判断是否重复, 314 | boolean isExist = start_end.get(startNodeId)!=null&&start_end.get(startNodeId)==endNodeId; 315 | //如果重复,跳过该关系 316 | if(isExist){ 317 | continue; 318 | } 319 | //没用重复,将将该关系添加到map中 320 | start_end.put(startNodeId,endNodeId); 321 | 322 | String relType = relationship.type(); 323 | 324 | //一个新的关系到来 325 | if(index==1){ 326 | relationBuffer.append("{"); 327 | }else{ 328 | relationBuffer.append(",{"); 329 | } 330 | relationBuffer.append("\"source\":"); 331 | relationBuffer.append(startNodeId); 332 | relationBuffer.append(","); 333 | relationBuffer.append("\"target\":"); 334 | relationBuffer.append(endNodeId); 335 | relationBuffer.append(","); 336 | relationBuffer.append("\"type\":"); 337 | relationBuffer.append("\""+relType+"\""); 338 | 339 | Iterator relKeys = relationship.keys().iterator(); 340 | 341 | while(relKeys.hasNext()){ 342 | String relKey = relKeys.next(); 343 | String relKeyValue = relationship.get(relKey).asObject().toString(); 344 | 345 | //去除空格 346 | //relKeyValue = relKeyValue.replaceAll("\\s",""); 347 | //去除制表符 348 | relKeyValue = relKeyValue.replaceAll("\t",""); 349 | //去除换行符 350 | relKeyValue = relKeyValue.replaceAll("\r",""); 351 | //去除回车符 352 | relKeyValue = relKeyValue.replaceAll("\n",""); 353 | 354 | //将双引号换成单引号 355 | relKeyValue = relKeyValue.replaceAll("\"","'"); 356 | 357 | relationBuffer.append(","); 358 | relationBuffer.append("\""+relKey+"\":"); 359 | relationBuffer.append("\""+relKeyValue+"\""); 360 | } 361 | relationBuffer.append("}"); 362 | /*if(i==cypherArrayList.size()-1&&!rels.hasNext()){ 363 | relationBuffer.append("}"); 364 | } 365 | else{ 366 | relationBuffer.append("},"); 367 | }*/ 368 | } 369 | } 370 | } 371 | } 372 | } 373 | relationBuffer.append("]"); 374 | close(); 375 | return relationBuffer; 376 | } 377 | //接下来是处理节点!!,这个有点复杂了!因为需要添加颜色属性! 378 | //执行多条cypher语句 379 | public static StringBuffer executeFindRelationNodesCyphers(ArrayList cypherArrayList){ 380 | //用一个set集合去除重复项 381 | Set nodeSet = new HashSet(); 382 | StringBuffer relationNodesBuffer = new StringBuffer(""); 383 | relationNodesBuffer.append("\"nodes\":["); 384 | getDriver(); 385 | 386 | int index = 0; 387 | 388 | try(Session session = driver.session()){ 389 | 390 | for(int i = 0;i list = record.values(); 397 | 398 | for(Value item:list){ 399 | Path path = item.asPath(); 400 | Iterator nodes = path.nodes().iterator(); 401 | 402 | while(nodes.hasNext()){ 403 | 404 | index++; 405 | 406 | Node node = nodes.next(); 407 | long nodeId = node.id(); 408 | boolean isExist = nodeSet.contains(nodeId); 409 | if(isExist) continue; 410 | 411 | if(index==1){ 412 | relationNodesBuffer.append("{"); 413 | } 414 | else{ 415 | relationNodesBuffer.append(",{"); 416 | } 417 | 418 | //没有重复,将nodeId添加到集合中 419 | nodeSet.add(nodeId); 420 | 421 | //得到node的类型 422 | Iterator nodeTypes = node.labels().iterator(); 423 | String nodeType = nodeTypes.next(); 424 | //从SystemInfo中得到NodeTypeKeys,好为新的节点类型分配颜色 425 | Set nodeTypeKeys = SystemInfo.getNodeTypeKeys(); 426 | 427 | //如果是新的节点类型,则分配颜色,并保持到SystemInfo中 428 | if(!nodeTypeKeys.contains(nodeType)){ 429 | int colorIndex = nodeTypeKeys.size(); 430 | //以防万一,所需颜色超过5,则随机一种颜色 431 | if(colorIndex>=5){ 432 | colorIndex = (int)Math.random()*5; 433 | } 434 | //得到颜色集合 435 | String[] colors = SystemInfo.getColor(); 436 | String color = colors[colorIndex]; 437 | //添加 438 | SystemInfo.addNodeType_Color(nodeType,color); 439 | //添加颜色属性 440 | relationNodesBuffer.append("\"color\":"); 441 | relationNodesBuffer.append("\""+color+"\""); 442 | } 443 | else{ 444 | //说明不是新的节点 445 | //通过nodeType得到该节点的颜色 446 | Map nodeType_Color = SystemInfo.getNodeType_Color(); 447 | String color = nodeType_Color.get(nodeType).toString(); 448 | //添加颜色属性 449 | relationNodesBuffer.append("\"color\":"); 450 | relationNodesBuffer.append("\""+color+"\""); 451 | } 452 | 453 | //添加id 454 | relationNodesBuffer.append(","); 455 | relationNodesBuffer.append("\"id\":"); 456 | relationNodesBuffer.append(nodeId); 457 | 458 | //添加type 459 | relationNodesBuffer.append(","); 460 | relationNodesBuffer.append("\"type\":"); 461 | relationNodesBuffer.append("\""+nodeType+"\""); 462 | 463 | //添加其他属性 464 | Iterator nodeKeys = node.keys().iterator(); 465 | 466 | while (nodeKeys.hasNext()){ 467 | String nodeKey = nodeKeys.next(); 468 | String nodeKeyValue = node.get(nodeKey).asObject().toString(); 469 | 470 | //去除空格 471 | //nodeKeyValue = nodeKeyValue.replaceAll("\\s",""); 472 | //去除制表符 473 | nodeKeyValue = nodeKeyValue.replaceAll("\t",""); 474 | //去除换行符 475 | nodeKeyValue = nodeKeyValue.replaceAll("\r",""); 476 | //去除回车符 477 | nodeKeyValue = nodeKeyValue.replaceAll("\n",""); 478 | 479 | //将双引号换成单引号 480 | nodeKeyValue = nodeKeyValue.replaceAll("\"","'"); 481 | 482 | relationNodesBuffer.append(","); 483 | relationNodesBuffer.append("\""+nodeKey+"\""); 484 | relationNodesBuffer.append(":"); 485 | relationNodesBuffer.append("\""+nodeKeyValue+"\""); 486 | } 487 | //添加完一个节点后 488 | relationNodesBuffer.append("}"); 489 | } 490 | 491 | } 492 | } 493 | } 494 | } 495 | relationNodesBuffer.append("]"); 496 | close(); 497 | return relationNodesBuffer; 498 | } 499 | 500 | } 501 | -------------------------------------------------------------------------------- /addClassUserInfo.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.zehua.admin.AdminInfo" %> 2 | <%@ page import="com.zehua.model.ClassBeanDBA" %> 3 | <%@ page import="com.zehua.model.ClassBean" %> 4 | <%@ page import="java.util.ArrayList" %><%-- 5 | Created by IntelliJ IDEA. 6 | User: 29306 7 | Date: 2018/6/6 8 | Time: 20:54 9 | To change this template use File | Settings | File Templates. 10 | --%> 11 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 12 | 13 | 14 | 15 | 16 | 我的 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | <% 28 | String[] allClasses; 29 | String[] allClassesId; 30 | String[] userClasses = AdminInfo.getClassTypeArray(); 31 | //先得到该年级,专业下的所有课程 32 | //通过gradeId,和majorId 33 | String gradeId = AdminInfo.getGradeId(); 34 | String majorId = AdminInfo.getMajorId(); 35 | 36 | ClassBeanDBA classBeanDBA = new ClassBeanDBA(); 37 | ArrayList classBeans= classBeanDBA.findItem(gradeId,majorId); 38 | allClasses = new String[classBeans.size()]; 39 | allClassesId = new String[classBeans.size()]; 40 | for(int i = 0;i 48 | 49 | 50 | 51 | 52 | 90 | 91 | 92 |
53 |
54 |

请选择你需要添加的课程

55 |
56 |
57 |
58 |
59 | <% 60 | for(int i = 0;i 73 |

74 | <% 75 | }else{ 76 | %> 77 |

78 | <% 79 | } 80 | } 81 | %> 82 | 83 |
84 |
85 |
86 |
87 | 88 | 89 |
93 | 94 | 95 | 96 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /admin/AdminInfo.java: -------------------------------------------------------------------------------- 1 | package com.zehua.admin; 2 | 3 | import org.bouncycastle.math.ec.custom.sec.SecT113R1Point; 4 | 5 | import java.util.HashMap; 6 | import java.util.HashSet; 7 | import java.util.Map; 8 | import java.util.Set; 9 | 10 | //目前只支持查询课程级别一下的关系 11 | //怎样使的在用户登录后,建立一个全局唯一的AdminInfo!!!!!!!!!!!!! 12 | public class AdminInfo { 13 | 14 | private static String username = "";//用户名 15 | private static String id = "";//用户id 16 | private static String gradeId = "";//年级id 17 | private static String gradeName = "";//年级 18 | private static String facultyId = "";//学院id 19 | private static String facultyName = "";//学院 20 | private static String majorId = "";//专业id 21 | private static String majorName = "";//专业 22 | private static Set classIdSet = new HashSet();//所选课的id 23 | private static Set classTypeSet = new HashSet();//所选课的名称 24 | private static Map> classType_subMap = new HashMap(); 25 | 26 | public static String getUsername() { 27 | return username; 28 | } 29 | 30 | public static void setUsername(String username) { 31 | AdminInfo.username = username; 32 | } 33 | 34 | public static String getId() { 35 | return id; 36 | } 37 | 38 | public static void setId(String id) { 39 | AdminInfo.id = id; 40 | } 41 | 42 | public static String getGradeId() { 43 | return gradeId; 44 | } 45 | 46 | public static void setGradeId(String gradeId) { 47 | AdminInfo.gradeId = gradeId; 48 | } 49 | 50 | public static String getGradeName() { 51 | return gradeName; 52 | } 53 | 54 | public static void setGradeName(String gradeName) { 55 | AdminInfo.gradeName = gradeName; 56 | } 57 | 58 | public static String getFacultyId() { 59 | return facultyId; 60 | } 61 | 62 | public static void setFacultyId(String facultyId) { 63 | AdminInfo.facultyId = facultyId; 64 | } 65 | 66 | public static String getFacultyName() { 67 | return facultyName; 68 | } 69 | 70 | public static void setFacultyName(String facultyName) { 71 | AdminInfo.facultyName = facultyName; 72 | } 73 | 74 | public static String getMajorId() { 75 | return majorId; 76 | } 77 | 78 | public static void setMajorId(String majorId) { 79 | AdminInfo.majorId = majorId; 80 | } 81 | 82 | public static String getMajorName() { 83 | return majorName; 84 | } 85 | 86 | public static void setMajorName(String majorName) { 87 | AdminInfo.majorName = majorName; 88 | } 89 | 90 | //添加课程Id 91 | public static void addClassIdSetItem(String... items){ 92 | int length = items.length; 93 | 94 | for(int i = 0;i classType_subSet = classType_subMap.get(classTypeSetItem); 150 | 151 | if(classType_subSet==null){ 152 | classType_subSet = new HashSet(); 153 | } 154 | int length = items.length; 155 | 156 | for(int i = 0;i al = new ArrayList<>(); 28 | 29 | for(int i = 0;i classBeans = classBeanDBA.findItem(classId); 46 | //只有一个 47 | String className = classBeans.get(0).getClassName(); 48 | //先检查是否已经存在!通过id 49 | int j = 0; 50 | int size = al.size(); 51 | for(;j bookBeans = bookBeanDBA.findItem(classId); 71 | 72 | for(int y = 0;y node_AttrKey_AttrValue_Map = 43 | nodeBeanDBA.getNodeAttrs(nodeType); 44 | //利用session传递对象 45 | session.setAttribute("node_AttrKey_AttrValue_Map",node_AttrKey_AttrValue_Map); 46 | 47 | session.setAttribute("nodeType",nodeType); 48 | String welcome = "欢迎来到添加 ("+nodeType+") 节点的界面"; 49 | request.getRequestDispatcher("inputInfo.jsp?welcome="+welcome).forward(request,response); 50 | } 51 | else if(flag.equals("addRel")){ 52 | RelationshipBeanDBA relationshipBeanDBA = new RelationshipBeanDBA(); 53 | 54 | String fromNodeType = request.getParameter("fromNodeType"); 55 | String relType = request.getParameter("relType"); 56 | String toNodeType = request.getParameter("toNodeType"); 57 | 58 | //得到了关系类型的名称,去查询name为(在sdu.zehuape@qq.com)的关系的所有属性 59 | Map relation_AttrKey_AttrValue_Map = 60 | relationshipBeanDBA.getRelAttrs(relType); 61 | //利用session传递对象 62 | session.setAttribute("relation_AttrKey_AttrValue_Map",relation_AttrKey_AttrValue_Map); 63 | 64 | session.setAttribute("fromNodeType",fromNodeType); 65 | session.setAttribute("relType",relType); 66 | session.setAttribute("toNodeType",toNodeType); 67 | 68 | String welcome = "欢迎来到添加 ("+fromNodeType+")"+"-["+relType+"]-"+"("+toNodeType+") 节点的界面"; 69 | request.getRequestDispatcher("inputInfo.jsp?welcome="+welcome).forward(request,response); 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /controller/AddNodeController2.java: -------------------------------------------------------------------------------- 1 | package com.zehua.controller; 2 | 3 | import com.zehua.model2.NodeBeanDBA; 4 | import com.zehua.model2.RelationshipBeanDBA; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | 13 | @WebServlet(name = "AddNodeController2") 14 | public class AddNodeController2 extends HttpServlet { 15 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 16 | doGet(request,response); 17 | } 18 | 19 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 20 | request.setCharacterEncoding("utf-8"); 21 | 22 | String result = request.getParameter("result"); 23 | String rowsLengthStr = request.getParameter("rowsLength"); 24 | String colsLengthStr = request.getParameter("colsLength"); 25 | int rowsLength = 0; 26 | int colsLength = 0; 27 | 28 | if(rowsLengthStr!=null){ 29 | rowsLength = Integer.parseInt(rowsLengthStr); 30 | } 31 | if(colsLengthStr!=null){ 32 | colsLength = Integer.parseInt(colsLengthStr); 33 | } 34 | 35 | //本来在输入的时候是可以输入空格的(或者什么都不输入!这个可以在那个jsp页面加一个判断,填入%作为标记,表示特殊情况) 36 | // 目前只考虑全输入的情况! 37 | 38 | //按空格分割 39 | String[] resultStrs = result.split(" "); 40 | for(int i = 0;ineo4j,所以会报500错误, 52 | //解决办法:将neo4j的驱动包,拷到jre中lib的ext目录下 53 | json = relationshipBeanDBA.lookInto(nodeType,nodeName); 54 | } 55 | //用户双击了节点! 56 | else{ 57 | //执行新的查询方法(允许多条查询语句语句同时进行) 58 | //先将语句加入到SystemInfo中,然后在得到全部的查询语句 59 | String cypher = ""; 60 | 61 | StringBuffer stringBuffer = new StringBuffer(""); 62 | stringBuffer.append("match p=(:"); 63 | stringBuffer.append(nodeType); 64 | stringBuffer.append("{"); 65 | stringBuffer.append("名称:"); 66 | stringBuffer.append("\""); 67 | stringBuffer.append(nodeName); 68 | stringBuffer.append("\""); 69 | stringBuffer.append("}"); 70 | stringBuffer.append(")"); 71 | stringBuffer.append("-[*..1]-() return p"); 72 | 73 | cypher = stringBuffer.toString(); 74 | 75 | SystemInfo.addCypher(cypher); 76 | 77 | //得到所有的查询语句 78 | ArrayList cypherArrayList = SystemInfo.getCypherArrayList(); 79 | 80 | /*for(int i = 0;i users = userBeanDBA.findItemWithName(username); 40 | if(users.size()!=0){ 41 | ArrayList userBean = userBeanDBA.findItemWithNameAndPas(username,password); 42 | //这里只会有一个用户 43 | if(userBean.size()!=0){ 44 | isOk = "true"; 45 | } 46 | else{ 47 | userPasswordError = "密码错误!"; 48 | } 49 | } 50 | else{ 51 | userNameError = "用户名不存在!"; 52 | } 53 | StringBuffer stringBuffer = new StringBuffer(""); 54 | stringBuffer.append("{"); 55 | stringBuffer.append("\""); 56 | stringBuffer.append("userNameError"); 57 | stringBuffer.append("\""); 58 | stringBuffer.append(":"); 59 | stringBuffer.append("\""); 60 | stringBuffer.append(userNameError); 61 | stringBuffer.append("\""); 62 | stringBuffer.append(","); 63 | stringBuffer.append("\""); 64 | stringBuffer.append("userPasswordError"); 65 | stringBuffer.append("\""); 66 | stringBuffer.append(":"); 67 | stringBuffer.append("\""); 68 | stringBuffer.append(userPasswordError); 69 | stringBuffer.append("\""); 70 | stringBuffer.append(","); 71 | stringBuffer.append("\""); 72 | stringBuffer.append("isOk"); 73 | stringBuffer.append("\""); 74 | stringBuffer.append(":"); 75 | stringBuffer.append("\""); 76 | stringBuffer.append(isOk); 77 | stringBuffer.append("\""); 78 | stringBuffer.append("}"); 79 | 80 | String json = stringBuffer.toString(); 81 | out.write(json); 82 | //查询数据库,新建一个AdminInfo 83 | 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /controller/UserInfoServlet.java: -------------------------------------------------------------------------------- 1 | package com.zehua.controller; 2 | 3 | import com.zehua.admin.AdminInfo; 4 | import com.zehua.model.*; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | 14 | @WebServlet(name = "UserInfoServlet") 15 | public class UserInfoServlet extends HttpServlet { 16 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 17 | this.doGet(request,response); 18 | } 19 | 20 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 21 | //这句话可以避免jsp页面传值到servlet页面时出现乱码 22 | request.setCharacterEncoding("utf-8"); 23 | 24 | //这句话可以避免从servlet到jsp页面出现乱码 25 | response.setContentType("text/html; charset=utf-8"); 26 | 27 | String username = request.getParameter("username"); 28 | String password = request.getParameter("password"); 29 | 30 | UserBeanDBA userBeanDBA = new UserBeanDBA(); 31 | //数据库验证 32 | ArrayList user = userBeanDBA.findItemWithNameAndPas(username,password); 33 | 34 | //在这里只会返回一个 35 | UserBean userBean = user.get(0); 36 | String id = userBean.getId(); 37 | //这里AdminInfo保存数据 38 | AdminInfo.setUsername(username); 39 | AdminInfo.setId(id); 40 | 41 | UserInfoConfigBeanDBA userInfoConfigBeanDBA = new UserInfoConfigBeanDBA(); 42 | ArrayList userInfoConfigBeans = userInfoConfigBeanDBA.findItem(id); 43 | 44 | //只会有一个 45 | //保存该用户的一些基本信息,也就是保存在AdminInfo中 46 | for(int i = 0;i userClassBeans = userClassBeanDBA.findItem(id); 60 | 61 | //这里会有多个,因为一个用户会与多门课发生联系 62 | for(int x = 0;x classBeans = classBeanDBA.findItem(classId); 70 | //只会有一个 71 | ClassBean classBean = classBeans.get(0); 72 | String className = classBean.getClassName(); 73 | //得到课程名称后,将它加入到AdminInfo中的ClassType域中 74 | AdminInfo.addClassTypeSetItem(className); 75 | //将课程编号加入到AdminInfo中 76 | AdminInfo.addClassIdSetItem(classId); 77 | 78 | //然后去书表中利用课程号,查找到书集 79 | BookBeanDBA bookBeanDBA = new BookBeanDBA(); 80 | ArrayList bookBeans = bookBeanDBA.findItem(classId); 81 | 82 | for(int y = 0;y gradeBeans = gradeBeanDBA.findItem(gradeId); 101 | //只会有一个 102 | String gradeName = gradeBeans.get(0).getGradeName(); 103 | //AdminInfo中的gradeName域 104 | AdminInfo.setGradeName(gradeName); 105 | //3、查找学院 106 | FacultyBeanDBA facultyBeanDBA = new FacultyBeanDBA(); 107 | ArrayList facultyBeans = facultyBeanDBA.findItem(facultyId); 108 | //只会有一个 109 | String facultyName = facultyBeans.get(0).getFacultyName(); 110 | //AdminInfo中的facultyName域 111 | AdminInfo.setFacultyName(facultyName); 112 | //4、查找专业 113 | MajorBeanDBA majorBeanDBA = new MajorBeanDBA(); 114 | ArrayList majorBeans = majorBeanDBA.findItem(majorId); 115 | //只有一个 116 | String majorName = majorBeans.get(0).getMajorName(); 117 | //AdminInfo中的majorName域 118 | AdminInfo.setMajorName(majorName); 119 | } 120 | //至此,配置信息全部完成 121 | //可以跳转了!! 122 | request.getRequestDispatcher("index.jsp").forward(request,response); 123 | 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /framework.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: 29306 4 | Date: 2018/5/26 5 | Time: 9:02 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | 13 | 14 | 我的 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 | 32 | 33 |
    34 |
  • 35 | 36 | 37 |
    38 | 39 |
    40 |
  • 41 |     42 |
  • 43 | 44 |
    45 | 课程: 46 | 47 | 50 | 51 |
    52 | 53 |
  • 54 |
  • 55 | 56 | 57 |
    58 | --> 59 | 62 |
    63 |
  • 64 |     65 |
  • 66 | 67 | 68 |
  • 69 |    70 |
  • 71 | 72 | 73 |
  • 74 | 75 |
76 | 96 |
97 | 98 |
99 |
100 | 101 | 117 |
118 |
119 |
120 | 121 | 122 | 123 |
124 | 125 | 128 |
129 | 130 | 131 | 197 | 198 | 204 | 205 | 206 | 207 | 208 | -------------------------------------------------------------------------------- /index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.zehua.admin.AdminInfo" %> 2 | <%@ page import="java.util.Map" %><%-- 3 | Created by IntelliJ IDEA. 4 | User: 29306 5 | Date: 2018/5/26 6 | Time: 9:02 7 | To change this template use File | Settings | File Templates. 8 | --%> 9 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 我的 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | <% 32 | //得到用户所选课程的集合 33 | String[] classTypeArray = AdminInfo.getClassTypeArray(); 34 | //得到一个映射关系,具体请看AdminInfo源码 35 | Map classType_subMap = AdminInfo.getClassType_subMap(); 36 | //将该映射关系转换成一个二维数组 37 | String[][] xx = new String[classTypeArray.length][]; 38 | 39 | for(int i = 0;i 45 | 46 |
47 |
48 | 49 | 50 |
    51 |
  • 52 | 53 | 54 |
    55 | 56 |
    57 |
  • 58 |     59 |
  • 60 | 61 |
    62 | 课程: 63 | 64 | 75 |
    76 | 77 |
  • 78 |
  • 79 | 80 | 81 |
    82 | --> 83 | 86 |
    87 |
  • 88 |     89 |
  • 90 | 91 | 92 |
  • 93 |    94 |
  • 95 | 96 | 97 |
  • 98 | 99 |
100 | 120 |
121 | 122 |
123 |
124 | 125 | 141 |
142 |
143 |
144 | 145 | 146 | 147 |
148 | 149 | 152 |
153 | 154 | 155 | 156 | 203 | 204 | 205 | 206 | 207 | 273 | 274 | 553 | 554 | 560 | 561 | 564 | 565 | 566 | 567 | -------------------------------------------------------------------------------- /inputInfo.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="java.util.Map" %> 2 | <%@ page import="java.util.Set" %><%-- 3 | Created by IntelliJ IDEA. 4 | User: 29306 5 | Date: 2018/5/26 6 | Time: 15:27 7 | To change this template use File | Settings | File Templates. 8 | --%> 9 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 10 | 11 | 12 | Title 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | <% 22 | 23 | //注意,java变量在js中不可以通过《%= %》这种方式来获取 24 | //可以通过:把java变量的值赋值给页面中的value,通过js去取; 25 | 26 | String welcome = request.getParameter("welcome"); 27 | 28 | String flag = session.getAttribute("flag").toString(); 29 | 30 | int length = 0; 31 | String[] attrKeys = null; 32 | if(flag.equals("addNode")){ 33 | Map node_AttrKey_AttrValue_Map = 34 | (Map) session.getAttribute("node_AttrKey_AttrValue_Map"); 35 | //得到所有的属性 36 | System.out.println(node_AttrKey_AttrValue_Map); 37 | Object[] attrKeysObj = node_AttrKey_AttrValue_Map.keySet().toArray(); 38 | length = attrKeysObj.length; 39 | attrKeys = new String[length]; 40 | 41 | for(int i = 0;i relation_AttrKey_AttrValue_Map = 48 | (Map) session.getAttribute("relation_AttrKey_AttrValue_Map"); 49 | //得到所有的属性 50 | Object[] attrKeysObj = relation_AttrKey_AttrValue_Map.keySet().toArray(); 51 | length = attrKeysObj.length-1; 52 | attrKeys = new String[length]; 53 | 54 | int index = 0; 55 | for(int i = 0;i 61 | 62 | 63 | 64 | 65 | 66 | 87 | 88 | 129 | 130 | 131 | 132 | 133 | 212 | 213 | 214 |
134 |

<%=welcome %>

135 |
136 |
137 |
138 |
139 |
140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
148 |
149 | 150 | 151 | 152 | <% 153 | if(flag.equals("addNode")){ 154 | for(int i = 0;i 156 | 157 | <% 158 | } 159 | } 160 | else if(flag.equals("addRel")){ 161 | %> 162 | 163 | 164 | 165 | <% 166 | for(int i = 0;i 168 | 169 | <% 170 | } 171 | } 172 | %> 173 | 174 | 175 | <% 176 | if(flag.equals("addNode")){ 177 | for(int i = 0;i 179 | 180 | <% 181 | } 182 | } 183 | %> 184 | <% 185 | if(flag.equals("addRel")){ 186 | for(int i = 0;i 188 | 189 | <% 190 | } 191 | } 192 | %> 193 | 194 | 195 |
196 |
197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 |
205 |
206 |
207 |
208 |
209 |
210 | 返回主界面 211 |
215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 | 3 | 4 | 5 | 6 | Home 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | 35 |
36 | 37 | 38 |
39 | 40 | 41 | 121 |
122 | 123 |
124 | 125 |
126 | 127 |
128 | 129 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /model/BookBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class BookBeanDBA { 8 | 9 | String bookId = null; 10 | String bookName = null; 11 | String classId = null; 12 | public void initializeInfo(BookBean bookBean){ 13 | bookId = bookBean.getBookId(); 14 | bookName = bookBean.getBookName(); 15 | classId = bookBean.getClassId(); 16 | } 17 | //增 18 | public boolean addItem(BookBean bookBean){ 19 | initializeInfo(bookBean); 20 | 21 | String sql = "insert into book values(?,?,?)"; 22 | String[] parameters = {bookId,bookName,classId}; 23 | 24 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 25 | 26 | return isSuccess; 27 | } 28 | //删 29 | public boolean deleteItem(BookBean bookBean){ 30 | initializeInfo(bookBean); 31 | 32 | String sql = "delete from book where bookId = ? and bookName = ? and classId = ?"; 33 | String[] parameters = {bookId,bookName,classId}; 34 | 35 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 36 | 37 | return isSuccess; 38 | } 39 | //改 40 | public boolean modifyItem(BookBean bookBean){ 41 | initializeInfo(bookBean); 42 | 43 | String sql = "update book set bookId = ? , bookName = ? where classId = ?"; 44 | String[] parameters = {bookId,bookName,classId}; 45 | 46 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 47 | 48 | return isSuccess; 49 | } 50 | //查,目前先只写按classId查询 51 | public ArrayList findItem(String classId){ 52 | 53 | ArrayList resultBookBeans = new ArrayList(); 54 | 55 | String sql = "select*from book where classId = ?"; 56 | String[] parameters = {classId}; 57 | 58 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 59 | int length = resultArray.length; 60 | for(int i = 0;i arrayList = resultArray[i]; 62 | 63 | String thisBookId = arrayList.get(0).toString(); 64 | String thisBookName = arrayList.get(1).toString(); 65 | String thisClassId = arrayList.get(2).toString(); 66 | 67 | BookBean thisBookBean = new BookBean(thisBookId,thisBookName,thisClassId); 68 | resultBookBeans.add(thisBookBean); 69 | 70 | } 71 | return resultBookBeans; 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /model/ClassBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class ClassBeanDBA { 8 | 9 | String classId = null; 10 | String className = null; 11 | String gradeId = null; 12 | String majorId = null; 13 | 14 | public void initializeInfo(ClassBean classBean){ 15 | classId = classBean.getClassId(); 16 | className = classBean.getClassName(); 17 | gradeId = classBean.getGradeId(); 18 | majorId = classBean.getMajorId(); 19 | } 20 | 21 | //增 22 | public boolean addItem(ClassBean classBean){ 23 | initializeInfo(classBean); 24 | 25 | String sql = "insert into class values(?,?,?,?)"; 26 | String[] parameters = {classId,className,gradeId,majorId}; 27 | 28 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 29 | 30 | return isSuccess; 31 | } 32 | //删 33 | public boolean deleteItem(ClassBean classBean){ 34 | initializeInfo(classBean); 35 | 36 | String sql = "delete from class where classId = ? , className = ? , gradeId = ? , majorId = ?"; 37 | String[] parameters = {classId,className,gradeId,majorId}; 38 | 39 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 40 | 41 | return isSuccess; 42 | 43 | } 44 | //改 45 | public boolean modifyItem(ClassBean classBean){ 46 | initializeInfo(classBean); 47 | 48 | String sql = "update class set classId = ? , className = ? where gradeId = ? and majorId = ?"; 49 | String[] parameters = {classId,className,gradeId,majorId}; 50 | 51 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 52 | 53 | return isSuccess; 54 | 55 | } 56 | //查,目前先只写按gradeId和majorId查询 57 | public ArrayList findItem(String gradeId,String majorId){ 58 | ArrayList resultClassBeans = new ArrayList(); 59 | 60 | String sql = "select * from class where gradeId = ? and majorId = ?"; 61 | String[] parameters = {gradeId,majorId}; 62 | 63 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 64 | int length = resultArray.length; 65 | for(int i = 0;i arrayList = resultArray[i]; 67 | 68 | String thisClassId = arrayList.get(0).toString(); 69 | String thisClassName = arrayList.get(1).toString(); 70 | String thisGradeId = arrayList.get(2).toString(); 71 | String thisMajorId = arrayList.get(3).toString(); 72 | 73 | ClassBean thisClassBean = new ClassBean(thisClassId,thisClassName,thisGradeId,thisMajorId); 74 | resultClassBeans.add(thisClassBean); 75 | 76 | } 77 | return resultClassBeans; 78 | } 79 | 80 | //查!按classId查 81 | public ArrayList findItem(String classId){ 82 | ArrayList resultClassBeans = new ArrayList(); 83 | 84 | String sql = "select * from class where classId = ?"; 85 | String[] parameters = {classId}; 86 | 87 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 88 | int length = resultArray.length; 89 | for(int i = 0;i arrayList = resultArray[i]; 91 | 92 | String thisClassId = arrayList.get(0).toString(); 93 | String thisClassName = arrayList.get(1).toString(); 94 | String thisGradeId = arrayList.get(2).toString(); 95 | String thisMajorId = arrayList.get(3).toString(); 96 | 97 | ClassBean thisClassBean = new ClassBean(thisClassId,thisClassName,thisGradeId,thisMajorId); 98 | resultClassBeans.add(thisClassBean); 99 | 100 | } 101 | return resultClassBeans; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /model/FacultyBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class FacultyBeanDBA { 8 | 9 | String facultyId = null; 10 | String facultyName = null; 11 | 12 | public void initializeInfo(FacultyBean facultyBean){ 13 | facultyId = facultyBean.getFacultyId(); 14 | facultyName = facultyBean.getFacultyName(); 15 | } 16 | 17 | public boolean addItem(FacultyBean facultyBean){ 18 | initializeInfo(facultyBean); 19 | 20 | String sql = "insert into faculty values(?,?)"; 21 | String[] parameters = {facultyId,facultyName}; 22 | 23 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 24 | 25 | return isSuccess; 26 | 27 | } 28 | 29 | public boolean deleteItem(FacultyBean facultyBean){ 30 | initializeInfo(facultyBean); 31 | 32 | String sql = "delete from faculty where facultyId = ? and facultyName = ?"; 33 | String[] parameters = {facultyId,facultyName}; 34 | 35 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 36 | 37 | return isSuccess; 38 | 39 | } 40 | 41 | public boolean modifyItem(FacultyBean facultyBean){ 42 | initializeInfo(facultyBean); 43 | 44 | String sql = "update faculty set facultyName = ? where facultyId = ?"; 45 | String[] parameters = {facultyName,facultyId}; 46 | 47 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 48 | 49 | return isSuccess; 50 | 51 | } 52 | 53 | public ArrayList findItem(String facultyId){ 54 | 55 | ArrayList resultFacultyBeans = new ArrayList(); 56 | 57 | String sql = "select*from faculty where facultyId = ?"; 58 | String[] parameters = {facultyId}; 59 | 60 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 61 | int length = resultArray.length; 62 | for(int i = 0;i arrayList = resultArray[i]; 64 | 65 | String thisFacultyId = arrayList.get(0).toString(); 66 | String thisFacultyName = arrayList.get(1).toString(); 67 | 68 | FacultyBean thisFacultyBean = new FacultyBean(thisFacultyId,thisFacultyName); 69 | resultFacultyBeans.add(thisFacultyBean); 70 | 71 | } 72 | return resultFacultyBeans; 73 | 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /model/GradeBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class GradeBeanDBA { 8 | 9 | String gradeId = null; 10 | String gradeName = null; 11 | 12 | public void initializeInfo(GradeBean gradeBean){ 13 | gradeId = gradeBean.getGradeId(); 14 | gradeName = gradeBean.getGradeName(); 15 | } 16 | 17 | public boolean addItem(GradeBean gradeBean){ 18 | initializeInfo(gradeBean); 19 | 20 | String sql = "insert into grade values(?,?)"; 21 | String[] parameters = {gradeId,gradeName}; 22 | 23 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 24 | 25 | return isSuccess; 26 | 27 | } 28 | 29 | public boolean deleteItem(GradeBean gradeBean){ 30 | initializeInfo(gradeBean); 31 | 32 | String sql = "delete from grade where gradeId = ? and gradeName = ?"; 33 | String[] parameters = {gradeId,gradeName}; 34 | 35 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 36 | 37 | return isSuccess; 38 | 39 | } 40 | 41 | public boolean modifyItem(GradeBean gradeBean){ 42 | initializeInfo(gradeBean); 43 | 44 | String sql = "update grade set gradeName = ? where gradeId = ?"; 45 | String[] parameters = {gradeName,gradeId}; 46 | 47 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 48 | 49 | return isSuccess; 50 | 51 | } 52 | 53 | public ArrayList findItem(String gradeId){ 54 | 55 | ArrayList resultGradeBeans = new ArrayList(); 56 | 57 | String sql = "select*from grade where gradeId = ?"; 58 | String[] parameters = {gradeId}; 59 | 60 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 61 | int length = resultArray.length; 62 | for(int i = 0;i arrayList = resultArray[i]; 64 | 65 | String thisGradeId = arrayList.get(0).toString(); 66 | String thisGradeName = arrayList.get(1).toString(); 67 | 68 | GradeBean thisGradeBean = new GradeBean(thisGradeId,thisGradeName); 69 | resultGradeBeans.add(thisGradeBean); 70 | 71 | } 72 | return resultGradeBeans; 73 | 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /model/MajorBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class MajorBeanDBA { 8 | 9 | String majorId = null; 10 | String majorName = null; 11 | String facultyId = null; 12 | 13 | public void initializeInfo(MajorBean majorBean){ 14 | majorId = majorBean.getMajorId(); 15 | majorName = majorBean.getMajorName(); 16 | facultyId = majorBean.getFacultyId(); 17 | } 18 | 19 | public ArrayList findItem(String majorId){ 20 | 21 | ArrayList resultMajorBeans = new ArrayList(); 22 | 23 | String sql = "select*from major where majorId = ?"; 24 | String[] parameters = {majorId}; 25 | 26 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 27 | int length = resultArray.length; 28 | for(int i = 0;i arrayList = resultArray[i]; 30 | 31 | String thisMajorId = arrayList.get(0).toString(); 32 | String thisMajorName = arrayList.get(1).toString(); 33 | String thisFacultyId = arrayList.get(2).toString(); 34 | 35 | 36 | MajorBean thisMajorBean = new MajorBean(thisMajorId,thisMajorName,thisFacultyId); 37 | resultMajorBeans.add(thisMajorBean); 38 | 39 | } 40 | return resultMajorBeans; 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /model/UserBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class UserBeanDBA { 8 | 9 | private String username; 10 | private String password; 11 | private String id; 12 | 13 | public void initializeInfo(UserBean userBean){ 14 | username = userBean.getUsername(); 15 | password = userBean.getPassword(); 16 | id = userBean.getId(); 17 | } 18 | 19 | //按用户名,密码查找 20 | public ArrayList findItemWithNameAndPas(String username, String password){ 21 | 22 | ArrayList resultUserBeans = new ArrayList(); 23 | 24 | String sql = "select*from user where username = ? and password = ?"; 25 | String[] parameters = {username,password}; 26 | 27 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 28 | int length = resultArray.length; 29 | for(int i = 0;i arrayList = resultArray[i]; 31 | 32 | String thisUsername = arrayList.get(0).toString(); 33 | String thisPassword = arrayList.get(1).toString(); 34 | String thisId = arrayList.get(2).toString(); 35 | 36 | UserBean thisUserBean = new UserBean(thisUsername,thisPassword,thisId); 37 | resultUserBeans.add(thisUserBean); 38 | 39 | } 40 | return resultUserBeans; 41 | 42 | } 43 | 44 | //按用户名查找 45 | public ArrayList findItemWithName(String username){ 46 | 47 | ArrayList resultUserBeans = new ArrayList(); 48 | 49 | String sql = "select*from user where username = ?"; 50 | String[] parameters = {username}; 51 | 52 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 53 | int length = resultArray.length; 54 | for(int i = 0;i arrayList = resultArray[i]; 56 | 57 | String thisUsername = arrayList.get(0).toString(); 58 | String thisPassword = arrayList.get(1).toString(); 59 | String thisId = arrayList.get(2).toString(); 60 | 61 | UserBean thisUserBean = new UserBean(thisUsername,thisPassword,thisId); 62 | resultUserBeans.add(thisUserBean); 63 | 64 | } 65 | return resultUserBeans; 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /model/UserClassBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class UserClassBeanDBA { 8 | 9 | private String id; 10 | private String classId; 11 | 12 | public void initializeInfo(UserClassBean userClassBean){ 13 | id = userClassBean.getId(); 14 | classId = userClassBean.getClassId(); 15 | } 16 | 17 | public boolean addItem(UserClassBean userClassBean){ 18 | initializeInfo(userClassBean); 19 | 20 | String sql = "insert into userClass values (?,?)"; 21 | String[] parameters = {id,classId}; 22 | 23 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 24 | 25 | return isSuccess; 26 | 27 | } 28 | 29 | //删 30 | public boolean deleteItem(UserClassBean userClassBean){ 31 | initializeInfo(userClassBean); 32 | 33 | String sql = "delete from userClass where id = ? and classId = ?"; 34 | String[] parameters = {id,classId}; 35 | 36 | boolean isSuccess = MysqlJDBC.executeUpdate(sql,parameters); 37 | 38 | return isSuccess; 39 | } 40 | 41 | public ArrayList findItem(String id){ 42 | 43 | ArrayList resulUserClassBeans = new ArrayList(); 44 | 45 | String sql = "select*from userClass where id = ?"; 46 | String[] parameters = {id}; 47 | 48 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 49 | int length = resultArray.length; 50 | for(int i = 0;i arrayList = resultArray[i]; 52 | 53 | String thisId = arrayList.get(0).toString(); 54 | String thisClassId = arrayList.get(1).toString(); 55 | 56 | UserClassBean thisUserClassBean = new UserClassBean(thisId,thisClassId); 57 | resulUserClassBeans.add(thisUserClassBean); 58 | 59 | } 60 | return resulUserClassBeans; 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /model/UserInfoConfigBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model; 2 | 3 | import com.zehua.MysqlJDBC; 4 | 5 | import java.util.ArrayList; 6 | 7 | public class UserInfoConfigBeanDBA { 8 | 9 | private String id; 10 | private String gradeId; 11 | private String facultyId; 12 | private String majorId; 13 | 14 | public void initializeInfo(UserInfoConfigBean userInfoConfigBean){ 15 | id = userInfoConfigBean.getId(); 16 | gradeId = userInfoConfigBean.getGradeId(); 17 | facultyId = userInfoConfigBean.getFacultyId(); 18 | majorId = userInfoConfigBean.getMajorId(); 19 | } 20 | 21 | public ArrayList findItem(String id){ 22 | 23 | ArrayList resultUserInfoConfigBeans = new ArrayList(); 24 | 25 | String sql = "select*from userInfoConfig where id = ?"; 26 | String[] parameters = {id}; 27 | 28 | ArrayList[] resultArray = MysqlJDBC.query(sql,parameters); 29 | int length = resultArray.length; 30 | for(int i = 0;i arrayList = resultArray[i]; 32 | 33 | String thisId = arrayList.get(0).toString(); 34 | String thisGradeId = arrayList.get(1).toString(); 35 | String thisFacultyId = arrayList.get(2).toString(); 36 | String thisMajorId = arrayList.get(3).toString(); 37 | 38 | UserInfoConfigBean thisUserInfoConfigBean = 39 | new UserInfoConfigBean(thisId,thisGradeId,thisFacultyId,thisMajorId); 40 | resultUserInfoConfigBeans.add(thisUserInfoConfigBean); 41 | 42 | } 43 | return resultUserInfoConfigBeans; 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /model2/NodeBeanDBA.java: -------------------------------------------------------------------------------- 1 | package com.zehua.model2; 2 | 3 | import com.zehua.Neo4jRestAPI; 4 | 5 | import java.util.Map; 6 | 7 | public class NodeBeanDBA { 8 | 9 | public void addNode(String nodeType,String[] nodeAttributesName,String[][] nodeAttributesValue){ 10 | for(int index = 0;index getNodeAttrs(String nodeType){ 41 | Map node_AttrKey_AttrValue_Map = null; 42 | 43 | String cypher = ""; 44 | StringBuffer stringBuffer= new StringBuffer(); 45 | stringBuffer.append("match (n:"); 46 | stringBuffer.append(nodeType); 47 | stringBuffer.append("{"); 48 | stringBuffer.append("名称"); 49 | stringBuffer.append(":"); 50 | stringBuffer.append("\""); 51 | stringBuffer.append("sdu.zehuape@qq.com"); 52 | stringBuffer.append("\""); 53 | stringBuffer.append("}) "); 54 | stringBuffer.append("return n"); 55 | 56 | cypher = stringBuffer.toString(); 57 | //执行 58 | node_AttrKey_AttrValue_Map = Neo4jRestAPI.executeFindNodeCypher(cypher); 59 | return node_AttrKey_AttrValue_Map; 60 | } 61 | 62 | /* 63 | public void deleteNode(String nodeType,String[] nodeAttributesName,String[] nodeAttributesValue){ 64 | String cypher = ""; 65 | StringBuffer stringBuffer = new StringBuffer(""); 66 | stringBuffer.append("match (n:"); 67 | stringBuffer.append(nodeType);//节点类型 68 | stringBuffer.append("{");//开始添加节点属性 69 | int i = 0; 70 | for(i = 0;i getRelAttrs(String relType){ 66 | Map relation_AttrKey_AttrValue_Map = null; 67 | 68 | String cypher = ""; 69 | StringBuffer stringBuffer= new StringBuffer(); 70 | stringBuffer.append("match ()-"); 71 | stringBuffer.append("[r:"); 72 | stringBuffer.append(relType); 73 | stringBuffer.append("{"); 74 | stringBuffer.append("name:"); 75 | stringBuffer.append("\""); 76 | stringBuffer.append("sdu.zehuape@qq.com"); 77 | stringBuffer.append("\""); 78 | stringBuffer.append("}"); 79 | stringBuffer.append("]"); 80 | stringBuffer.append("-() "); 81 | stringBuffer.append("return r"); 82 | 83 | cypher = stringBuffer.toString(); 84 | 85 | System.out.println(cypher); 86 | //执行 87 | relation_AttrKey_AttrValue_Map = Neo4jRestAPI.executeFindRelAttrCypher(cypher); 88 | return relation_AttrKey_AttrValue_Map; 89 | } 90 | //写入json文件,查找 91 | public String lookInto(String nodeType, String nodeName){ 92 | String cypher = ""; 93 | 94 | if(nodeName==null||nodeName==""){ 95 | StringBuffer stringBuffer1 = new StringBuffer(""); 96 | stringBuffer1.append("match p=(:"); 97 | stringBuffer1.append(nodeType); 98 | stringBuffer1.append(")"); 99 | stringBuffer1.append("-[*..1]-() return p"); 100 | 101 | cypher = stringBuffer1.toString(); 102 | }else{ 103 | StringBuffer stringBuffer2 = new StringBuffer(""); 104 | stringBuffer2.append("match p=(:"); 105 | stringBuffer2.append(nodeType); 106 | stringBuffer2.append("{"); 107 | stringBuffer2.append("名称:"); 108 | stringBuffer2.append("\""); 109 | stringBuffer2.append(nodeName); 110 | stringBuffer2.append("\""); 111 | stringBuffer2.append("}"); 112 | stringBuffer2.append(")"); 113 | stringBuffer2.append("-[*..1]-() return p"); 114 | 115 | cypher = stringBuffer2.toString(); 116 | 117 | //先清空,再将cypher语句加入到SystemInfo中 118 | 119 | } 120 | SystemInfo.clearAll(); 121 | SystemInfo.addCypher(cypher); 122 | //System.out.println(cypher); 123 | 124 | 125 | StringBuffer relationBuffer = Neo4jRestAPI.executeFindRelationCypher(cypher); 126 | StringBuffer relationNodesBuffer = Neo4jRestAPI.executeFindRelationNodesCypher(cypher); 127 | ToJson toJson = new ToJson(relationNodesBuffer,relationBuffer); 128 | //toJson.writeJson(); 129 | //System.out.println(toJson.getJson()); 130 | 131 | return toJson.getJson(); 132 | } 133 | //针对的是多条查询语句 134 | public String lookIntos(ArrayList cypherArrayList){ 135 | String cypher = ""; 136 | 137 | StringBuffer relationBuffer = Neo4jRestAPI.executeFindRelationCyphers(cypherArrayList); 138 | StringBuffer relationNodesBuffer = Neo4jRestAPI.executeFindRelationNodesCyphers(cypherArrayList); 139 | ToJson toJson = new ToJson(relationNodesBuffer,relationBuffer); 140 | 141 | //toJson.writeJson(); 142 | 143 | return toJson.getJson(); 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /preparations/GetNodes.java: -------------------------------------------------------------------------------- 1 | package com.zehua.neo4jJava; 2 | 3 | import org.neo4j.driver.v1.*; 4 | import org.neo4j.driver.v1.types.Node; 5 | 6 | import java.util.HashMap; 7 | import java.util.Iterator; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public class GetNodes { 12 | 13 | static Driver driver = null; 14 | 15 | public static void getDriver(){ 16 | String uri = "Bolt://localhost:7687"; 17 | String user = "";//写你自己的neo4j的用户名 18 | String password = "";//写你自己的neo4j的密码 19 | driver = GraphDatabase.driver(uri, AuthTokens.basic(user,password)); 20 | } 21 | 22 | public static void close(){ 23 | if(driver!=null){ 24 | driver.close(); 25 | } 26 | } 27 | 28 | //node 29 | public static void getNodesInfo(String cypher){ 30 | getDriver(); 31 | 32 | Map node_AttrKey_AttrValue_Map = new HashMap<>(); 33 | 34 | try(Session session = driver.session()){ 35 | StatementResult result = session.run(cypher); 36 | 37 | while(result.hasNext()){ 38 | Record record = result.next(); 39 | List value = record.values(); 40 | 41 | for(Value i:value){ 42 | Node node = i.asNode(); 43 | Iterator keys = node.keys().iterator(); 44 | 45 | Iterator nodeTypes = node.labels().iterator(); 46 | String nodeType = nodeTypes.next().toString(); 47 | System.out.println("节点类型:"+nodeType); 48 | System.out.println("节点属性如下:"); 49 | while(keys.hasNext()){ 50 | String attrKey = (String)keys.next(); 51 | String attrValue = node.get(attrKey).asString(); 52 | System.out.println(attrKey+"-------"+attrValue); 53 | } 54 | System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 55 | } 56 | } 57 | } 58 | close(); 59 | } 60 | 61 | public static void main(String... args){ 62 | 63 | String cypher = "match (n:数据库章节{名称:'关系数据库'}) return n"; 64 | getNodesInfo(cypher); 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /preparations/GetPaths.java: -------------------------------------------------------------------------------- 1 | package com.zehua.neo4jJava; 2 | 3 | import org.neo4j.driver.v1.*; 4 | import org.neo4j.driver.v1.types.Path; 5 | import org.neo4j.driver.v1.types.Relationship; 6 | 7 | import java.util.Iterator; 8 | import java.util.List; 9 | 10 | public class GetPaths { 11 | 12 | static Driver driver = null; 13 | 14 | public static void getDriver(){ 15 | String uri = "Bolt://localhost:7687"; 16 | String user = "";//写你自己的neo4j的用户名 17 | String password = "";//写你自己的neo4j的密码 18 | driver = GraphDatabase.driver(uri, AuthTokens.basic(user,password)); 19 | } 20 | 21 | public static void close(){ 22 | if(driver!=null){ 23 | driver.close(); 24 | } 25 | } 26 | 27 | public static void getPathsInfo(String cypher){ 28 | getDriver(); 29 | 30 | int count = 0; 31 | try(Session session = driver.session()){ 32 | //result包含了所有的path 33 | StatementResult result = session.run(cypher); 34 | 35 | while(result.hasNext()){ 36 | Record record = result.next(); 37 | List value = record.values(); 38 | 39 | for(Value i:value){ 40 | Path path = i.asPath(); 41 | //处理路径中的关系 42 | Iterator relationships = path.relationships().iterator(); 43 | 44 | //Iterator nodes = path.nodes().iterator();//得到path中的节点 45 | 46 | while(relationships.hasNext()){ 47 | count++; 48 | Relationship relationship = relationships.next(); 49 | 50 | long startNodeId = relationship.startNodeId(); 51 | long endNodeId = relationship.endNodeId(); 52 | String relType = relationship.type(); 53 | 54 | System.out.println("关系"+count+": "); 55 | System.out.println("关系类型:"+relType); 56 | System.out.println("from "+startNodeId+"-----"+"to "+endNodeId); 57 | 58 | System.out.println("关系属性如下:"); 59 | 60 | //得到关系属性的健 61 | Iterator relKeys = relationship.keys().iterator(); 62 | //这里处理关系属性 63 | while(relKeys.hasNext()){ 64 | String relKey = relKeys.next(); 65 | String relValue = relationship.get(relKey).asObject().toString(); 66 | System.out.println(relKey+"-----"+relValue); 67 | } 68 | System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 69 | } 70 | } 71 | } 72 | } 73 | close(); 74 | } 75 | 76 | public static void main(String... args){ 77 | 78 | String cypher = "match p=shortestPath((n1:数据库课程{名称:'数据库'})-[*..6]-(n2:数据库知识点{名称:'概念结构设计'})) return p"; 79 | getPathsInfo(cypher); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /preparations/JsonFormat.java: -------------------------------------------------------------------------------- 1 | package com.zehua.neo4jJava; 2 | 3 | import org.neo4j.driver.v1.*; 4 | import org.neo4j.driver.v1.types.Node; 5 | import org.neo4j.driver.v1.types.Path; 6 | import org.neo4j.driver.v1.types.Relationship; 7 | 8 | import java.util.*; 9 | 10 | public class JsonFormat { 11 | 12 | static Driver driver = null; 13 | 14 | public static void getDriver(){ 15 | String uri = "Bolt://localhost:7687"; 16 | String user = "";//写你自己的neo4j的用户名 17 | String password = "";//写你自己的neo4j的密码 18 | driver = GraphDatabase.driver(uri, AuthTokens.basic(user,password)); 19 | } 20 | 21 | public static void close(){ 22 | if(driver!=null){ 23 | driver.close(); 24 | } 25 | } 26 | 27 | //返回关系的StringBuffer,为可视化做准备!json文件 28 | public static StringBuffer executeFindRelationCypher(String cypher){ 29 | //关系的StringBuffer,json格式 30 | StringBuffer relationBuffer = new StringBuffer(""); 31 | relationBuffer.append("\"links\":[");//return "links":[ 32 | getDriver(); 33 | 34 | try(Session session = driver.session()){ 35 | //result包含了所有的path 36 | StatementResult result = session.run(cypher); 37 | 38 | while(result.hasNext()){ 39 | Record record = result.next(); 40 | List value = record.values(); 41 | 42 | for(Value i:value){ 43 | Path path = i.asPath(); 44 | Iterator relationships = path.relationships().iterator(); 45 | 46 | while(relationships.hasNext()){ 47 | Relationship relationship = relationships.next(); 48 | 49 | long startNodeId = relationship.startNodeId(); 50 | long endNodeId = relationship.endNodeId(); 51 | String relType = relationship.type(); 52 | 53 | //得到关系属性的健 54 | Iterator relKeys = relationship.keys().iterator(); 55 | 56 | relationBuffer.append("{"); 57 | relationBuffer.append("\"source\":"); 58 | relationBuffer.append(startNodeId); 59 | relationBuffer.append(","); 60 | relationBuffer.append("\"target\":"); 61 | relationBuffer.append(endNodeId); 62 | relationBuffer.append(","); 63 | relationBuffer.append("\"type\":"); 64 | relationBuffer.append("\""+relType+"\""); 65 | 66 | //这里处理关系属性 67 | while(relKeys.hasNext()){ 68 | String relKey = relKeys.next(); 69 | String relValue = relationship.get(relKey).asObject().toString(); 70 | 71 | //去除制表符 72 | relValue = relValue.replaceAll("\t",""); 73 | //去除换行符 74 | relValue= relValue.replaceAll("\r",""); 75 | //去除回车符 76 | relValue = relValue.replaceAll("\n",""); 77 | 78 | //将双引号换成单引号 79 | relValue = relValue.replaceAll("\"","'"); 80 | 81 | relationBuffer.append(","); 82 | relationBuffer.append("\""+relKey+"\""); 83 | relationBuffer.append(":"); 84 | relationBuffer.append("\""+relValue+"\""); 85 | } 86 | if(!relationships.hasNext()&&!result.hasNext()){ 87 | relationBuffer.append("}"); 88 | } 89 | else { 90 | //如果是最后一个,只需要添加}即可 91 | relationBuffer.append("},"); 92 | } 93 | 94 | } 95 | } 96 | } 97 | } 98 | relationBuffer.append("]"); 99 | close(); 100 | return relationBuffer; 101 | } 102 | 103 | //返回关系中节点的StringBuffer,为可视化做准备!json文件,需要增加节点的类型 104 | public static StringBuffer executeFindRelationNodesCypher(String cypher) { 105 | //用一个set集合去除重复项 106 | Set nodeSet = new HashSet(); 107 | StringBuffer relationNodesBuffer = new StringBuffer(""); 108 | relationNodesBuffer.append("\"nodes\":["); 109 | getDriver(); 110 | 111 | try(Session session = driver.session()){ 112 | StatementResult result = session.run(cypher); 113 | 114 | while(result.hasNext()){ 115 | Record record = result.next(); 116 | List value = record.values(); 117 | 118 | for(Value i:value){ 119 | 120 | Path path = i.asPath(); 121 | Iterator nodes = path.nodes().iterator(); 122 | 123 | while(nodes.hasNext()){ 124 | Node node = nodes.next(); 125 | //在增加节点以前,先判断是否在集合中 126 | boolean isExist = nodeSet.contains(node.id()); 127 | if (isExist) continue; 128 | Iterator nodeKeys = node.keys().iterator(); 129 | relationNodesBuffer.append("{"); 130 | 131 | //节点属性 132 | while(nodeKeys.hasNext()){ 133 | String nodeKey = nodeKeys.next(); 134 | relationNodesBuffer.append("\""+nodeKey+"\":"); 135 | //node.get(nodeKey).toString(); 136 | //System.out.println(node.get(nodeKey).asObject().toString()); 137 | String content = node.get(nodeKey).asObject().toString(); 138 | 139 | //去除制表符 140 | content = content.replaceAll("\t",""); 141 | //去除换行符 142 | content = content.replaceAll("\r",""); 143 | //去除回车符 144 | content = content.replaceAll("\n",""); 145 | 146 | //将双引号换成单引号 147 | content = content.replaceAll("\"","'"); 148 | 149 | relationNodesBuffer.append("\""+content+"\","); 150 | } 151 | relationNodesBuffer.append("\"id\":"); 152 | relationNodesBuffer.append(node.id()); 153 | //添加节点类型!不知道为什么取得节点类型用的是labels,可能一个节点可以属于多个类别 154 | //但是我们这里只属于一个类别! 155 | Iterator nodeTypes = node.labels().iterator(); 156 | //得到节点类型了! 157 | String nodeType = nodeTypes.next(); 158 | 159 | relationNodesBuffer.append(","); 160 | relationNodesBuffer.append("\"type\":"); 161 | relationNodesBuffer.append("\""+nodeType+"\""); 162 | 163 | //将节点添加到set集合中 164 | nodeSet.add(node.id()); 165 | 166 | if(!nodes.hasNext()&&!result.hasNext()){ 167 | relationNodesBuffer.append("}"); 168 | } 169 | else{ 170 | relationNodesBuffer.append("},"); 171 | } 172 | } 173 | } 174 | } 175 | } 176 | int bufferLength = relationNodesBuffer.length(); 177 | char lastChar = relationNodesBuffer.charAt(bufferLength-1); 178 | if(lastChar==','){ 179 | String str = relationNodesBuffer.substring(0,relationNodesBuffer.length()-1); 180 | relationNodesBuffer = relationNodesBuffer.replace(0,bufferLength,str); 181 | } 182 | relationNodesBuffer.append("]"); 183 | close(); 184 | return relationNodesBuffer; 185 | } 186 | 187 | public static void main(String... args){ 188 | 189 | String cypher = "match p=(:数据库课程)-[*..1]-() return p"; 190 | 191 | StringBuffer relationBuffer = executeFindRelationCypher(cypher); 192 | StringBuffer relationNodesBuffer = executeFindRelationNodesCypher(cypher); 193 | ToJson toJson = new ToJson(relationNodesBuffer,relationBuffer); 194 | 195 | toJson.writeJson(); 196 | 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /preparations/displayInWeb.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /preparations/increaseAndDecrease.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Title 5 | 6 | 7 | 8 | 9 | 10 | 11 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
61 |
62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
74 |
75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
83 | 84 | 85 | -------------------------------------------------------------------------------- /preparations/myStyle.css: -------------------------------------------------------------------------------- 1 | textarea{ 2 | font-size: 20px; 3 | border-bottom: hidden; 4 | border-top: hidden; 5 | border-left: hidden; 6 | border-right: hidden; 7 | width: 100%; 8 | } 9 | 10 | .layui-form-select dl dd, .layui-form-select dl dt{ 11 | background-color: #01AAED; 12 | } 13 | -------------------------------------------------------------------------------- /showUserInfoConfig.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.zehua.admin.AdminInfo" %><%-- 2 | Created by IntelliJ IDEA. 3 | User: 29306 4 | Date: 2018/6/6 5 | Time: 19:06 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | Title 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | <% 26 | String username = AdminInfo.getUsername(); 27 | String id = AdminInfo.getId(); 28 | String gradName = AdminInfo.getGradeName(); 29 | String facultyName = AdminInfo.getFacultyName(); 30 | String majorName = AdminInfo.getMajorName(); 31 | 32 | //得到课程集合 33 | String[] classTypeArray = AdminInfo.getClassTypeArray(); 34 | 35 | %> 36 | 37 | 38 | 39 | 40 | 98 | 99 | 100 |
41 | 42 |

你的基本信息页面

43 |
44 |
45 |
46 |
47 | 姓名:<%=username %>
48 | 编号:<%=id %>
49 | 年级:<%=gradName %>
50 | 学院:<%=facultyName %>
51 | 专业:<%=majorName %>
52 |
53 |
54 |
55 |
56 |
57 |
58 | 59 | 60 | <% 61 | for(int i = 0;i 63 | 64 | 65 | 66 | 86 | 87 | <% 88 | } 89 | %> 90 | 91 | 94 | 95 |
<%=classTypeArray[i] %> 67 |
68 |
69 |
70 |
71 | 81 |
82 |
83 |
84 |
85 |
92 | 93 |
96 | 97 |
101 | 102 | 108 | 109 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /systemInfo/SystemInfo.java: -------------------------------------------------------------------------------- 1 | package systemInfo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | //1、这个类包含用户某一系列操作查询的所有语句(即用户双击了节点) 9 | //而当用户重新输入数据时,该类将重新保存用户的查询产生的查询语句! 10 | //2、这个类还包含一个颜色数组color[5] 11 | // (数组大小为5 已经足够!因为可能展现给用户的节点类别不超过5) 12 | //展现的不同的节点类用不同的颜色 13 | //3、包含一个节点-颜色的对应关系 14 | public class SystemInfo { 15 | 16 | //用于保存每次用户点击“查询”后的所有查询语句,用于实现“双击”节点后弹出下一层 17 | public static ArrayList cypherArrayList = new ArrayList<>(); 18 | //默认为5种颜色 19 | public static final String[] COLOR = {"blue","yellow","green","pink","purple"}; 20 | //将一种颜色和一种类型的节点对应起来 21 | public static Map nodeType_Color = new HashMap(); 22 | 23 | //添加cypher语句 24 | public static void addCypher(String... cyphers){ 25 | int length = cyphers.length; 26 | 27 | for(int i = 0;i getCypherArrayList(){ 34 | return cypherArrayList; 35 | } 36 | //清空所有 37 | public static void clearAll(){ 38 | cypherArrayList.clear(); 39 | nodeType_Color.clear(); 40 | } 41 | //返回颜色数组 42 | public static String[] getColor(){ 43 | return COLOR; 44 | } 45 | //添加节点和颜色的映射 46 | public static void addNodeType_Color(String nodeType,String color){ 47 | nodeType_Color.put(nodeType,color); 48 | } 49 | //返回节点和颜色的映射 50 | public static Map getNodeType_Color(){ 51 | return nodeType_Color; 52 | } 53 | //返回已经分配颜色的节点集合 54 | public static Set getNodeTypeKeys(){ 55 | return nodeType_Color.keySet(); 56 | } 57 | 58 | } 59 | --------------------------------------------------------------------------------