package model; public class CrawlResult { private String title; private double price; private double originalPrice; private double discount; private String imageUrl; private String author; public CrawlResult(String title, double price, double originalPrice, double discount, String imageUrl, String author) { this.title = title; this.price = price; this.originalPrice = originalPrice; this.discount = discount; this.imageUrl = imageUrl; this.author = author; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public double getOriginalPrice() { return originalPrice; } public void setOriginalPrice(double originalPrice) { this.originalPrice = originalPrice; } public double getDiscount() { return discount; } public void setDiscount(double discount) { this.discount = discount; } public String getImageUrl() { return imageUrl; } public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } @Override public String toString() { return String.format("%s,%.2f,%.2f,%.1f,%s,%s", title, price, originalPrice, discount, imageUrl, author); } public String toJson() { return String.format( "{\"title\":\"%s\",\"price\":%.2f,\"originalPrice\":%.2f,\"discount\":%.1f,\"imageUrl\":\"%s\",\"author\":\"%s\"}", escapeJson(title), price, originalPrice, discount, escapeJson(imageUrl), escapeJson(author) ); } private String escapeJson(String str) { if (str == null) return ""; return str.replace("\\", "\\\\") .replace("\"", "\\\"") .replace("\n", "\\n") .replace("\r", "\\r") .replace("\t", "\\t"); } }