parent
6ffb4ccf2e
commit
b78505e119
@ -0,0 +1,50 @@
|
||||
package com.markma.leave_manager_spb.controller;
|
||||
|
||||
import com.markma.leave_manager_spb.entity.Comment;
|
||||
import com.markma.leave_manager_spb.repository.CommentRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/comment")
|
||||
|
||||
public class CommentHandler {
|
||||
@Autowired
|
||||
private CommentRepository commentRepository;
|
||||
|
||||
@GetMapping("/findAllPaged/{page}/{size}")
|
||||
public List<Comment> findAllPaged(@PathVariable("page") int page, @PathVariable("size") int size) {
|
||||
List<Comment> Cs = commentRepository.findAll();
|
||||
List<Comment> LeftCs = new ArrayList<Comment>();
|
||||
int num = 0, pagemin = (page - 1) * size + 1, pagemax = page * size;
|
||||
for (int i = 0; i < Cs.size(); i++) {
|
||||
num++;
|
||||
if (num >= pagemin && num <= pagemax) LeftCs.add(Cs.get(i));
|
||||
}
|
||||
return LeftCs;
|
||||
}
|
||||
|
||||
@GetMapping("/findAllNum")
|
||||
public Integer findAllNum() {
|
||||
return commentRepository.findAll().size();
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/save")
|
||||
public String save(@RequestBody Comment comment) {
|
||||
Comment result = commentRepository.save(comment);
|
||||
if (result != null) {
|
||||
return "success";
|
||||
} else {
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("delete/{id}")
|
||||
public void delete(@PathVariable Integer id) {
|
||||
commentRepository.deleteById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.markma.leave_manager_spb.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Comment {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
private String comment_detail;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.markma.leave_manager_spb.repository;
|
||||
|
||||
import com.markma.leave_manager_spb.entity.Comment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CommentRepository extends JpaRepository<Comment, Integer> {
|
||||
}
|
Loading…
Reference in new issue