You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Neo4jTest.java 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.xkcoding.neo4j;
  2. import cn.hutool.json.JSONUtil;
  3. import com.xkcoding.neo4j.model.Lesson;
  4. import com.xkcoding.neo4j.model.Student;
  5. import com.xkcoding.neo4j.service.NeoService;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.junit.Test;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import java.util.stream.Collectors;
  13. /**
  14. * <p>
  15. * 测试Neo4j
  16. * </p>
  17. *
  18. * @package: com.xkcoding.neo4j
  19. * @description: 测试Neo4j
  20. * @author: yangkai.shen
  21. * @date: Created in 2018-12-24 15:17
  22. * @copyright: Copyright (c) 2018
  23. * @version: V1.0
  24. * @modified: yangkai.shen
  25. */
  26. @Slf4j
  27. public class Neo4jTest extends SpringBootDemoNeo4jApplicationTests {
  28. @Autowired
  29. private NeoService neoService;
  30. /**
  31. * 测试保存
  32. */
  33. @Test
  34. public void testSave() {
  35. neoService.initData();
  36. }
  37. /**
  38. * 测试删除
  39. */
  40. @Test
  41. public void testDelete() {
  42. neoService.delete();
  43. }
  44. /**
  45. * 测试查询 鸣人 学了哪些课程
  46. */
  47. @Test
  48. public void testFindLessonsByStudent() {
  49. // 深度为1,则课程的任教老师的属性为null
  50. // 深度为2,则会把课程的任教老师的属性赋值
  51. List<Lesson> lessons = neoService.findLessonsFromStudent("漩涡鸣人", 2);
  52. lessons.forEach(lesson -> log.info("【lesson】= {}", JSONUtil.toJsonStr(lesson)));
  53. }
  54. /**
  55. * 测试查询班级人数
  56. */
  57. @Test
  58. public void testCountStudent() {
  59. Long all = neoService.studentCount(null);
  60. log.info("【全校人数】= {}", all);
  61. Long seven = neoService.studentCount("第七班");
  62. log.info("【第七班人数】= {}", seven);
  63. }
  64. /**
  65. * 测试根据课程查询同学关系
  66. */
  67. @Test
  68. public void testFindClassmates() {
  69. Map<String, List<Student>> classmates = neoService.findClassmatesGroupByLesson();
  70. classmates.forEach((k, v) -> log.info("因为一起上了【{}】这门课,成为同学关系的有:{}", k, JSONUtil.toJsonStr(v.stream()
  71. .map(Student::getName)
  72. .collect(Collectors.toList()))));
  73. }
  74. /**
  75. * 查询所有师生关系,包括班主任/学生,任课老师/学生
  76. */
  77. @Test
  78. public void testFindTeacherStudent() {
  79. Map<String, Set<Student>> teacherStudent = neoService.findTeacherStudent();
  80. teacherStudent.forEach((k, v) -> log.info("【{}】教的学生有 {}", k, JSONUtil.toJsonStr(v.stream()
  81. .map(Student::getName)
  82. .collect(Collectors.toList()))));
  83. }
  84. }

一个用来深度学习并实战 spring boot 的项目,目前总共包含 66 个集成demo,已经完成 55 个。