22301102 | b108437 | 2025-06-01 16:44:23 +0800 | [diff] [blame] | 1 | package com.pt.entity; |
| 2 | |
| 3 | import jakarta.persistence.Entity; |
| 4 | import jakarta.persistence.GeneratedValue; |
| 5 | import jakarta.persistence.GenerationType; |
| 6 | import jakarta.persistence.Id; |
| 7 | |
| 8 | import java.time.LocalDateTime; |
| 9 | |
| 10 | @Entity |
| 11 | public class Resource { |
| 12 | |
| 13 | @Id |
| 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 15 | private int resourceId; |
| 16 | |
| 17 | private String name; |
| 18 | private double size; |
| 19 | |
| 20 | private LocalDateTime publishTime; |
| 21 | private String author; |
| 22 | |
| 23 | private String description; |
22301102 | bc6da0a | 2025-06-02 17:47:29 +0800 | [diff] [blame] | 24 | private byte[] torrentData; |
22301102 | b108437 | 2025-06-01 16:44:23 +0800 | [diff] [blame] | 25 | |
| 26 | public Resource() { |
| 27 | } |
| 28 | |
| 29 | public Resource(int resourceId, String name, double size, LocalDateTime publishTime, String author) { |
| 30 | this.resourceId = resourceId; |
| 31 | this.name = name; |
| 32 | this.size = size; |
| 33 | this.publishTime = publishTime; |
| 34 | this.author = author; |
| 35 | } |
| 36 | |
| 37 | public int getResourceId() { |
| 38 | return resourceId; |
| 39 | } |
| 40 | public void setResourceId(int resourceId) { |
| 41 | this.resourceId = resourceId; |
| 42 | } |
| 43 | public String getName() { |
| 44 | return name; |
| 45 | } |
| 46 | public void setName(String name) { |
| 47 | this.name = name; |
| 48 | } |
| 49 | public double getSize() { |
| 50 | return size; |
| 51 | } |
| 52 | public void setSize(double size) { |
| 53 | this.size = size; |
| 54 | } |
| 55 | public LocalDateTime getPublishTime() { |
| 56 | return publishTime; |
| 57 | } |
| 58 | public void setPublishTime(LocalDateTime publishTime) { |
| 59 | this.publishTime = publishTime; |
| 60 | } |
| 61 | public String getAuthor() { |
| 62 | return author; |
| 63 | } |
| 64 | public void setAuthor(String author) { |
| 65 | this.author = author; |
| 66 | } |
| 67 | public String getDescription() { |
| 68 | return description; |
| 69 | } |
| 70 | public void setDescription(String description) { |
| 71 | this.description = description; |
| 72 | } |
22301102 | bc6da0a | 2025-06-02 17:47:29 +0800 | [diff] [blame] | 73 | public byte[] getTorrentData() { |
| 74 | return torrentData; |
| 75 | } |
| 76 | |
| 77 | public void setTorrentData(byte[] torrentData) { |
| 78 | this.torrentData = torrentData; |
| 79 | } |
22301102 | b108437 | 2025-06-01 16:44:23 +0800 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * 重写toString方法,将资源信息以JSON字符串形式返回 |
| 83 | */ |
| 84 | @Override |
| 85 | public String toString() { |
| 86 | return "{" + |
| 87 | "\"resourceId\":" + resourceId + |
| 88 | ", \"name\":\"" + name + "\"" + |
| 89 | ", \"size\":" + size + |
| 90 | ", \"publishTime\":\"" + publishTime + "\"" + |
| 91 | ", \"author\":\"" + author + "\"" + |
| 92 | ", \"description\":\"" + description + "\"" + |
| 93 | '}'; |
| 94 | } |
| 95 | } |