student相关repository初步构建完成
This commit is contained in:
parent
e6d2941f3c
commit
ccb1cb3682
@ -0,0 +1,37 @@
|
|||||||
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.student.Comment;
|
||||||
|
import com.codesdream.ase.repository.student.CommentRepository;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController("test")
|
||||||
|
public class TestController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
CommentRepository commentRepository;
|
||||||
|
|
||||||
|
@RequestMapping
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public boolean test() throws InterruptedException {
|
||||||
|
|
||||||
|
int userId = 1;
|
||||||
|
for (int i = 0;i < 10; i++){
|
||||||
|
Comment comment = new Comment();
|
||||||
|
comment.setUserId(userId);
|
||||||
|
comment.setContext(new Integer(i).toString());
|
||||||
|
commentRepository.save(comment);
|
||||||
|
Thread.sleep(20);
|
||||||
|
}
|
||||||
|
Thread.sleep(1000);
|
||||||
|
List<Comment> comments = commentRepository.findByUserId(new Integer(userId).toString(),
|
||||||
|
Sort.by(Sort.Direction.ASC, "date"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package com.codesdream.ase.model.student;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table
|
@Table
|
||||||
@ -17,4 +18,7 @@ public class Comment {
|
|||||||
|
|
||||||
// 评论内容
|
// 评论内容
|
||||||
String context;
|
String context;
|
||||||
|
|
||||||
|
// 评论时间
|
||||||
|
Date date = new Date();
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ public class Honor {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
|
String studentId;
|
||||||
|
|
||||||
// 荣誉描述
|
// 荣誉描述
|
||||||
String description;
|
String description;
|
||||||
|
|
||||||
|
@ -5,12 +5,9 @@ import com.codesdream.ase.model.permission.User;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import javax.annotation.Generated;
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class Student extends User {
|
public class Student extends User {
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.codesdream.ase.repository.student;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.student.Comment;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CommentRepository extends JpaRepository<Comment, Integer> {
|
||||||
|
List<Comment> findByUserId(String id, Sort sort);
|
||||||
|
|
||||||
|
List<Comment> findByUserId(String id);
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.codesdream.ase.repository.student;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.student.Course;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CourseRepository extends JpaRepository<Course, Integer> {
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.codesdream.ase.repository.student;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.student.Honor;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface HonorRepository extends JpaRepository<Honor, Integer> {
|
||||||
|
List<Honor> findByStudentId(String studentId, Sort sort);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.codesdream.ase.repository.student;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.student.Notification;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface NotificationRepository extends JpaRepository<Notification, Integer> {
|
||||||
|
Optional<Notification> findByTitle(String title);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.codesdream.ase.repository.student;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.student.Student;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface StudentRepository extends JpaRepository<Student, Integer> {
|
||||||
|
Optional<Student> findByStudentId(String studentId);
|
||||||
|
|
||||||
|
List<Student> findByName(String name, Sort sort);
|
||||||
|
|
||||||
|
List<Student> findByName(String name);
|
||||||
|
}
|
35
src/test/java/com/codesdream/ase/test/JpaTest.java
Normal file
35
src/test/java/com/codesdream/ase/test/JpaTest.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package com.codesdream.ase.test;
|
||||||
|
|
||||||
|
import com.codesdream.ase.component.ASESpringUtil;
|
||||||
|
import com.codesdream.ase.model.student.Comment;
|
||||||
|
import com.codesdream.ase.repository.student.CommentRepository;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class JpaTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ASESpringUtil aseSpringUtil;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws InterruptedException {
|
||||||
|
|
||||||
|
CommentRepository commentRepository = aseSpringUtil.getBean(CommentRepository.class);
|
||||||
|
int userId = 1;
|
||||||
|
for (int i = 0;i < 10; i++){
|
||||||
|
Comment comment = new Comment();
|
||||||
|
comment.setUserId(userId);
|
||||||
|
comment.setContext(new Integer(i).toString());
|
||||||
|
commentRepository.save(comment);
|
||||||
|
Thread.sleep(20);
|
||||||
|
}
|
||||||
|
Thread.sleep(1000);
|
||||||
|
List<Comment> comments = commentRepository.findByUserId(new Integer(userId).toString(),
|
||||||
|
Sort.by(Sort.Direction.ASC, "date"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user