Преглед изворни кода

重构代码,修复swaggerUI不能显示的bug

宋悦 пре 8 година
родитељ
комит
9555b316ad

+ 13 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/CourseApi.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
  * Created by songyue on 17/1/14.
  */
 @RestController
-@RequestMapping("${app.api.root}")
+@RequestMapping("${app.api.root}/course")
 public class CourseApi {
 
     @Autowired
@@ -23,38 +23,38 @@ public class CourseApi {
     @Autowired
     CourseService courseService;
 
-    @ApiOperation(value="查询所有课程",notes = "分页")
-    @GetMapping("/course/all/{curPage}/{pageSize}")
+    @ApiOperation(value="查询所有课程",notes="分页")
+    @GetMapping("/all/{curPage}/{pageSize}")
     public ResponseEntity getAllCourse(@ModelAttribute Course courseCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
         return courseService.getAllCourse(courseCriteria,new PageRequest(curPage - 1,pageSize));
     }
 
-    @ApiOperation(value="查询所有课程",notes = "不分页")
-    @GetMapping("/course/all")
+    @ApiOperation(value="查询所有课程",notes="不分页")
+    @GetMapping("/all")
     public ResponseEntity getAllCourse(@ModelAttribute Course courseCriteria){
         return courseService.getAllCourse(courseCriteria);
     }
 
-    @ApiOperation(value="按ID查询课程",notes = "ID查询")
-    @GetMapping("/course/{id}")
+    @ApiOperation(value="按ID查询课程",notes="ID查询")
+    @GetMapping("/{id}")
     public ResponseEntity<Course> getCourseById(@PathVariable Long id){
         return courseService.getCourseById(id);
     }
 
-    @ApiOperation(value="新增课程",notes = "新增")
-    @PostMapping("/course")
+    @ApiOperation(value="新增课程",notes="新增")
+    @PostMapping
     public ResponseEntity addCourse(@ModelAttribute Course course){
         return courseService.saveCourse(course);
     }
 
-    @ApiOperation(value="更新课程",notes = "更新")
-    @PutMapping("/course")
+    @ApiOperation(value="更新课程",notes="更新")
+    @PutMapping
     public ResponseEntity updateCourse(@ModelAttribute Course course){
         return courseService.saveCourse(course);
     }
 
-    @ApiOperation(value="按ID删除课程",notes = "删除")
-    @DeleteMapping("/course/{id}")
+    @ApiOperation(value="按ID删除课程",notes="删除")
+    @DeleteMapping("/{id}")
     public ResponseEntity deleteCourse(@PathVariable Long id){
         return courseService.deleteCourse(id);
     }

+ 13 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/LearnCenterApi.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
  * Created by songyue on 17/1/14.
  */
 @RestController
-@RequestMapping("${app.api.root}")
+@RequestMapping("${app.api.root}/learn_enter")
 public class LearnCenterApi {
 
     @Autowired
@@ -23,38 +23,38 @@ public class LearnCenterApi {
     @Autowired
     LearnCenterService learnCenterService;
 
-    @ApiOperation(value="查询所有学习中心",notes = "分页")
-    @GetMapping("/learn_enter/all/{curPage}/{pageSize}")
+    @ApiOperation(value="查询所有学习中心",notes="分页")
+    @GetMapping("/all/{curPage}/{pageSize}")
     public ResponseEntity getAllLearnCenter(@ModelAttribute LearnCenter learnCenterCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
         return learnCenterService.getAllLearnCenter(learnCenterCriteria,new PageRequest(curPage - 1,pageSize));
     }
 
-    @ApiOperation(value="查询所有学习中心",notes = "不分页")
-    @GetMapping("/learn_enter/all")
+    @ApiOperation(value="查询所有学习中心",notes="不分页")
+    @GetMapping("/all")
     public ResponseEntity getAllLearnCenter(@ModelAttribute LearnCenter learnCenterCriteria){
         return learnCenterService.getAllLearnCenter(learnCenterCriteria);
     }
 
-    @ApiOperation(value="按ID查询学习中心",notes = "ID查询")
-    @GetMapping("/learn_enter/{id}")
+    @ApiOperation(value="按ID查询学习中心",notes="ID查询")
+    @GetMapping("/{id}")
     public ResponseEntity<LearnCenter> getLearnCenterById(@PathVariable Long id){
         return learnCenterService.getLearnCenterById(id);
     }
 
-    @ApiOperation(value="新增学习中心",notes = "新增")
-    @PostMapping("/learn_enter")
+    @ApiOperation(value="新增学习中心",notes="新增")
+    @PostMapping
     public ResponseEntity addLearnCenter(@ModelAttribute LearnCenter learnCenter){
         return learnCenterService.saveLearnCenter(learnCenter);
     }
 
-    @ApiOperation(value="更新学习中心",notes = "更新")
-    @PutMapping("/learn_enter")
+    @ApiOperation(value="更新学习中心",notes="更新")
+    @PutMapping
     public ResponseEntity updateLearnCenter(@ModelAttribute LearnCenter learnCenter){
         return learnCenterService.saveLearnCenter(learnCenter);
     }
 
-    @ApiOperation(value="按ID删除学习中心",notes = "删除")
-    @DeleteMapping("/learn_enter/{id}")
+    @ApiOperation(value="按ID删除学习中心",notes="删除")
+    @DeleteMapping("/{id}")
     public ResponseEntity deleteLearnCenter(@PathVariable Long id){
         return learnCenterService.deleteLearnCenter(id);
     }

+ 13 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/SchoolApi.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
  * Created by songyue on 17/1/14.
  */
 @RestController
-@RequestMapping("${app.api.root}")
+@RequestMapping("${app.api.root}/school")
 public class SchoolApi {
 
     @Autowired
@@ -23,38 +23,38 @@ public class SchoolApi {
     @Autowired
     SchoolService schoolService;
 
-    @ApiOperation(value="查询所有学校",notes = "分页")
-    @GetMapping("/school/all/{curPage}/{pageSize}")
+    @ApiOperation(value="查询所有学校",notes="分页")
+    @GetMapping("/all/{curPage}/{pageSize}")
     public ResponseEntity getAllSchool(@ModelAttribute School schoolCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
         return schoolService.getAllSchool(schoolCriteria,new PageRequest(curPage - 1,pageSize));
     }
 
-    @ApiOperation(value="查询所有学校",notes = "不分页")
-    @GetMapping("/school/all")
+    @ApiOperation(value="查询所有学校",notes="不分页")
+    @GetMapping("/all")
     public ResponseEntity getAllSchool(@ModelAttribute School schoolCriteria){
         return schoolService.getAllSchool(schoolCriteria);
     }
 
-    @ApiOperation(value="按ID查询学校",notes = "ID查询")
-    @GetMapping("/school/{id}")
+    @ApiOperation(value="按ID查询学校",notes="ID查询")
+    @GetMapping("/{id}")
     public ResponseEntity<School> getSchoolById(@PathVariable Long id){
         return schoolService.getSchoolById(id);
     }
 
-    @ApiOperation(value="新增学校",notes = "新增")
-    @PostMapping("/school")
+    @ApiOperation(value="新增学校",notes="新增")
+    @PostMapping
     public ResponseEntity addSchool(@ModelAttribute School school){
         return schoolService.saveSchool(school);
     }
 
-    @ApiOperation(value="更新学校",notes = "更新")
-    @PutMapping("/school")
+    @ApiOperation(value="更新学校",notes="更新")
+    @PutMapping
     public ResponseEntity updateSchool(@ModelAttribute School school){
         return schoolService.saveSchool(school);
     }
 
-    @ApiOperation(value="按ID删除学校",notes = "删除")
-    @DeleteMapping("/school/{id}")
+    @ApiOperation(value="按ID删除学校",notes="删除")
+    @DeleteMapping("/{id}")
     public ResponseEntity deleteSchool(@PathVariable Long id){
         return schoolService.deleteSchool(id);
     }

+ 13 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/StudentApi.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
  * Created by songyue on 17/1/14.
  */
 @RestController
-@RequestMapping("${app.api.root}")
+@RequestMapping("${app.api.root}/student")
 public class StudentApi {
 
     @Autowired
@@ -23,38 +23,38 @@ public class StudentApi {
     @Autowired
     StudentService studentService;
 
-    @ApiOperation(value="查询所有学生",notes = "分页")
-    @GetMapping("/student/all/{curPage}/{pageSize}")
+    @ApiOperation(value="查询所有学生",notes="分页")
+    @GetMapping("/all/{curPage}/{pageSize}")
     public ResponseEntity getAllStudent(@ModelAttribute Student studentCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
         return studentService.getAllStudent(studentCriteria,new PageRequest(curPage - 1,pageSize));
     }
 
-    @ApiOperation(value="查询所有学生",notes = "不分页")
-    @GetMapping("/student/all")
+    @ApiOperation(value="查询所有学生",notes="不分页")
+    @GetMapping("/all")
     public ResponseEntity getAllStudent(@ModelAttribute Student studentCriteria){
         return studentService.getAllStudent(studentCriteria);
     }
 
-    @ApiOperation(value="按ID查询学生",notes = "ID查询")
-    @GetMapping("/student/{id}")
+    @ApiOperation(value="按ID查询学生",notes="ID查询")
+    @GetMapping("/{id}")
     public ResponseEntity<Student> getStudentById(@PathVariable Long id){
         return studentService.getStudentById(id);
     }
 
-    @ApiOperation(value="新增学生",notes = "新增")
-    @PostMapping("/student")
+    @ApiOperation(value="新增学生",notes="新增")
+    @PostMapping
     public ResponseEntity addStudent(@ModelAttribute Student student){
         return studentService.saveStudent(student);
     }
 
-    @ApiOperation(value="更新学生",notes = "更新")
-    @PutMapping("/student")
+    @ApiOperation(value="更新学生",notes="更新")
+    @PutMapping
     public ResponseEntity updateStudent(@ModelAttribute Student student){
         return studentService.saveStudent(student);
     }
 
-    @ApiOperation(value="按ID删除学生",notes = "删除")
-    @DeleteMapping("/student/{id}")
+    @ApiOperation(value="按ID删除学生",notes="删除")
+    @DeleteMapping("/{id}")
     public ResponseEntity deleteStudent(@PathVariable Long id){
         return studentService.deleteStudent(id);
     }

+ 13 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/UserApi.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
  * Created by songyue on 17/1/13.
  */
 @RestController
-@RequestMapping("${app.api.root}")
+@RequestMapping("${app.api.root}/user")
 public class UserApi {
 
     @Autowired
@@ -23,38 +23,38 @@ public class UserApi {
     @Autowired
     UserRepo userRepo;
 
-    @ApiOperation(value="查询所有用户",notes = "分页")
-    @GetMapping("/user/all/{curPage}/{pageSize}")
+    @ApiOperation(value="查询所有用户",notes="分页")
+    @GetMapping("/all/{curPage}/{pageSize}")
     public ResponseEntity getAllUser(@ModelAttribute User userCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
         return userService.getAllUser(userCriteria,new PageRequest(curPage - 1,pageSize));
     }
 
-    @ApiOperation(value="查询所有用户",notes = "不分页")
-    @GetMapping("/user/all")
+    @ApiOperation(value="查询所有用户",notes="不分页")
+    @GetMapping("/all")
     public ResponseEntity getAllUser(@ModelAttribute User userCriteria){
         return userService.getAllUser(userCriteria);
     }
 
-    @ApiOperation(value="按ID查询用户",notes = "ID查询")
-    @GetMapping("/user/{id}")
+    @ApiOperation(value="按ID查询用户",notes="ID查询")
+    @GetMapping("/{id}")
     public ResponseEntity<User> getUserById(@PathVariable Long id){
         return userService.getUserById(id);
     }
 
-    @ApiOperation(value="新增用户",notes = "新增")
-    @PostMapping("/user")
+    @ApiOperation(value="新增用户",notes="新增")
+    @PostMapping
     public ResponseEntity addUser(@ModelAttribute User user){
         return userService.saveUser(user);
     }
 
-    @ApiOperation(value="更新用户",notes = "更新")
-    @PutMapping("/user")
+    @ApiOperation(value="更新用户",notes="更新")
+    @PutMapping
     public ResponseEntity updateUser(@ModelAttribute User user){
         return userService.saveUser(user);
     }
 
-    @ApiOperation(value="按ID删除用户",notes = "删除")
-    @DeleteMapping("/user/{id}")
+    @ApiOperation(value="按ID删除用户",notes="删除")
+    @DeleteMapping("/{id}")
     public ResponseEntity deleteUser(@PathVariable Long id){
         return userService.deleteUser(id);
     }

+ 6 - 0
core-domain/pom.xml

@@ -12,6 +12,12 @@
     <artifactId>core-domain</artifactId>
 
     <dependencies>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>${mysql.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>

+ 3 - 3
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Course.java

@@ -20,7 +20,7 @@ public class Course implements Serializable{
 	
     @Id
     @GeneratedValue
-    private long id;
+    private Long id;
 
 	@NotNull
 	private String code;
@@ -31,11 +31,11 @@ public class Course implements Serializable{
 	@Temporal(TemporalType.DATE)
 	private Date createTime;
     
-	public long getId() {
+	public Long getId() {
 		return id;
 	}
 
-	public void setId(long id) {
+	public void setId(Long id) {
 		this.id = id;
 	}
 

+ 0 - 2
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/LearnCenter.java

@@ -1,8 +1,6 @@
 package cn.com.qmth.examcloud.service.core.entity;
 
 import cn.com.qmth.examcloud.service.core.enums.isValid;
-import org.springframework.data.annotation.Id;
-
 import javax.persistence.*;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;

+ 10 - 11
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/School.java

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.service.core.entity;
 
 import cn.com.qmth.examcloud.service.core.enums.isValid;
-import org.springframework.data.annotation.Id;
 
 import javax.persistence.*;
 import javax.validation.constraints.NotNull;
@@ -34,9 +33,9 @@ public class School implements Serializable{
     @Enumerated(EnumType.STRING)
     private isValid isvalid;
 
-    @OneToMany(cascade = {CascadeType.ALL})
-    @JoinColumn(name="schoolId")
-    private List<LearnCenter> learnCenters;
+//    @OneToMany(cascade = {CascadeType.ALL})
+//    @JoinColumn(name="schoolId")
+//    private List<LearnCenter> learnCenters;
 
     public static long getSerialVersionUID() {
         return serialVersionUID;
@@ -82,13 +81,13 @@ public class School implements Serializable{
         this.isvalid = isvalid;
     }
 
-    public List<LearnCenter> getLearnCenters() {
-        return learnCenters;
-    }
-
-    public void setLearnCenters(List<LearnCenter> learnCenters) {
-        this.learnCenters = learnCenters;
-    }
+//    public List<LearnCenter> getLearnCenters() {
+//        return learnCenters;
+//    }
+//
+//    public void setLearnCenters(List<LearnCenter> learnCenters) {
+//        this.learnCenters = learnCenters;
+//    }
 
     public School() {
     }

+ 4 - 3
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Student.java

@@ -15,12 +15,13 @@ public class Student implements Serializable {
 
 	@Id
 	@GeneratedValue
-	private long id;
+	private Long id;
 
 	@OneToOne
 	@JoinColumn(name = "userId")
 	private User user;
 
+	@NotNull
 	private String name;
 
 	private String studentCode;
@@ -41,11 +42,11 @@ public class Student implements Serializable {
 		return serialVersionUID;
 	}
 
-	public long getId() {
+	public Long getId() {
 		return id;
 	}
 
-	public void setId(long id) {
+	public void setId(Long id) {
 		this.id = id;
 	}
 

+ 1 - 2
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/User.java

@@ -1,8 +1,6 @@
 package cn.com.qmth.examcloud.service.core.entity;
 
 import cn.com.qmth.examcloud.service.core.enums.isValid;
-import org.springframework.data.annotation.Id;
-
 import javax.persistence.*;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
@@ -27,6 +25,7 @@ public class User implements Serializable{
     @NotNull
     private String loginName;
 
+    @Temporal(value = TemporalType.DATE)
     private Date createTime;
 
     @NotNull

+ 29 - 0
core-main/pom.xml

@@ -11,6 +11,11 @@
 
     <artifactId>core-main</artifactId>
     <dependencies>
+        <dependency>
+            <groupId>cn.com.qmth.examcloud.service</groupId>
+            <artifactId>core-api</artifactId>
+            <version>0.1.0</version>
+        </dependency>
         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-feign</artifactId>
@@ -19,6 +24,10 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-eureka</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
@@ -40,4 +49,24 @@
             <version>2.6.1</version>
         </dependency>
     </dependencies>
+
+    <build>
+        <!-- 为jar包取名 -->
+        <finalName>ExamCloud-service-core</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring.boot.version}</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

+ 1 - 0
core-main/src/main/resources/application.properties

@@ -3,6 +3,7 @@ spring.datasource.username=root
 spring.datasource.password=root
 spring.datasource.validation-query=SELECT 1 FROM DUAL
 spring.datasource.test-on-borrow=true
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
 
 #redis
 #spring.redis.host=192.168.199.102

+ 16 - 35
pom.xml

@@ -19,7 +19,7 @@
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
-        <version>1.4.0.RELEASE</version>
+        <version>1.4.3.RELEASE</version>
     </parent>
 
 
@@ -40,6 +40,7 @@
         <!-- maven plugins -->
         <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
         <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
+        <spring.boot.version>1.4.3.RELEASE</spring.boot.version>
     </properties>
 
     <dependencyManagement>
@@ -79,42 +80,22 @@
     <build>
         <plugins>
             <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring.boot.version}</version>
+                <configuration><!-- 指定该Main Class为全局的唯一入口 -->
+                    <mainClass>cn.com.qmth.examcloud.service.core.Application</mainClass>
+                    <layout>ZIP</layout>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
-
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-            </plugin>
-
         </plugins>
-
-        <pluginManagement>
-            <plugins>
-
-                <plugin>
-                    <groupId>org.apache.maven.plugins</groupId>
-                    <artifactId>maven-surefire-plugin</artifactId>
-                    <version>${maven-surefire-plugin.version}</version>
-                    <configuration>
-                        <testFailureIgnore>true</testFailureIgnore>
-                    </configuration>
-                </plugin>
-
-                <plugin>
-                    <groupId>org.apache.maven.plugins</groupId>
-                    <artifactId>maven-compiler-plugin</artifactId>
-                    <version>${maven-compiler-plugin.version}</version>
-                    <configuration>
-                        <source>1.8</source>
-                        <target>1.8</target>
-                        <compilerArgument>-proc:none</compilerArgument>
-                    </configuration>
-                </plugin>
-
-            </plugins>
-        </pluginManagement>
     </build>
 
 </project>