Books列表增加分页;默认每页20条
This commit is contained in:
@@ -9,6 +9,8 @@ import net.alawn.bill.repository.ItemRepo;
|
||||
import net.alawn.bill.repository.UserRepo;
|
||||
import net.alawn.bill.security.AuthUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,7 @@ public class BillController {
|
||||
log.info("book:" + book.getTotalAmount());
|
||||
|
||||
/** 费率计算 */
|
||||
book.setFee(book.getTotalAmount().multiply(BigDecimal.valueOf(feeRate)));
|
||||
book.setTotalFee(book.getTotalAmount().multiply(BigDecimal.valueOf(feeRate)));
|
||||
bookRepo.save(book);
|
||||
bookRepo.flush();
|
||||
return ResponseEntity.ok(book);
|
||||
@@ -72,11 +73,13 @@ public class BillController {
|
||||
|
||||
@RequestMapping(value = "/books",method = RequestMethod.GET)
|
||||
public ResponseEntity<List<Book>> fetchBooks(){
|
||||
// public ResponseEntity<Page<Book>> fetchBooks(){
|
||||
AuthUser authUser = (AuthUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
long userId = authUser.getId();
|
||||
|
||||
List<Book> books = bookRepo.findByUserIdOrderByCreateTimeDesc(userId);
|
||||
|
||||
return ResponseEntity.ok(books);
|
||||
// List<Book> books = bookRepo.findByUserIdOrderByCreateTimeDesc(userId);
|
||||
Page<Book> books = bookRepo.findByUserIdOrderByCreateTimeDesc(userId, PageRequest.of(0,20));
|
||||
// return ResponseEntity.ok(books);
|
||||
return ResponseEntity.ok(books.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package net.alawn.bill.entity.po;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.NotFound;
|
||||
import org.hibernate.annotations.NotFoundAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Entity
|
||||
@Table(name = "t_bill_premission")
|
||||
@ToString(exclude = {"user"})
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" },ignoreUnknown = true)
|
||||
@DynamicUpdate
|
||||
public class Premission extends EntityId{
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@NotFound(action = NotFoundAction.IGNORE)
|
||||
// @JoinColumn(name = "userId", referencedColumnName = "id")
|
||||
@JoinColumn(name = "userId", referencedColumnName = "id")
|
||||
// @MapsId("username")
|
||||
@MapsId("id")
|
||||
private User user;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return this == o || o instanceof Premission
|
||||
&& id != null
|
||||
&& id.equals(((Premission) o).id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user