实体类
public class Product {
private Integer id;
private String img;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Product{" +
"id=" + id +
", img='" + img + '\'' +
", name='" + name + '\'' +
'}';
}
}
Vo
import java.util.List;
public class ProductVo {
private List<Product> product;
public List<Product> getProduct() {
return product;
}
public void setProduct(List<Product> product) {
this.product = product;
}
@Override
public String toString() {
return "ProductVo{" +
"product=" + product +
'}';
}
}
控制层
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping(value = "/getProductList")
public String getProductList() {
Product product1 = new Product();
Product product2 = new Product();
Product product3 = new Product();
product1.setName("product1");product1.setId(1);product1.setImg("iiiiiiiiiiiiiiiiiiiiiiiiiii");
product2.setName("product2");product2.setId(2);product2.setImg("iiiiiiiiiiiiiiiiiiiiiiiiiii");
product3.setName("product3");product3.setId(3);product3.setImg("iiiiiiiiiiiiiiiiiiiiiiiiiii");
List<Product> list = new ArrayList<>();
list.add(product1);list.add(product2);list.add(product3);
ProductVo productVo = new ProductVo();
productVo.setProduct(list);
return JSONObject.toJSONString(productVo);
}
}
访问接口