---
# System prepended metadata

title: 後端 0530

---

# 後端 0530
# cartbean
```
package com.ctbcbank.demo.lab.bean;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@Data
@Table
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class CartBean {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
//	@Column(name = "cart_id")
	private Long id;
	private String name;
	private int price;
	private String detail;

	public CartBean(String name, int price, String detail) {
		super();
		this.name = name;
		this.price = price;
		this.detail = detail;
	}
}

```
# customerbean
```
package com.ctbcbank.demo.lab.bean;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CustomerBean {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;
	private String name;
	private String password;
	
	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name="product_cart", 
	joinColumns = {@JoinColumn(name="customer_id")},
    inverseJoinColumns = {
            @JoinColumn(name = "product_id")
        })
    private List<ProductBean> products = new ArrayList<ProductBean>();
	
	public CustomerBean(String name, String password) {
		super();
		this.name = name;
		this.password = password;
//		this.cart=cart;
	}
}



```
#  productbean
```
package com.ctbcbank.demo.lab.bean;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@NoArgsConstructor
public class ProductBean {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String name;
	private int price;
	private String filePath;
	private String detail;
	private Date updateDate = new Date();

	@ManyToOne
	@JoinColumn(name = "PRODUCTCATEGORY_ID_FK")
	@JsonIgnoreProperties(ignoreUnknown = true,value = {"products"})
	ProductCategoryBean productCategory;
	
	@ManyToMany(cascade = CascadeType.ALL, mappedBy="products")
	@JsonIgnore
    private List<CustomerBean> customers;

	public ProductBean(String name, int price, String filePath, String detail) {
		super();
		this.name = name;
		this.price = price;
		this.filePath = filePath;
		this.detail = detail;
	}

}

```
# productCategoryBean
```
package com.ctbcbank.demo.lab.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@Data
@NoArgsConstructor
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
public class ProductCategoryBean implements Serializable{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;
	private String name;

	@OneToMany(mappedBy = "productCategory", cascade = CascadeType.REMOVE)
	private List<ProductBean> products = new ArrayList<>();
}

```
# cartbeancontroller
```
package com.ctbcbank.demo.lab.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ctbcbank.demo.lab.bean.CartBean;
import com.ctbcbank.demo.lab.service.CartBeanService;

import lombok.extern.slf4j.Slf4j;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/api/cart")
public class CartBeanController {
	@Autowired
	private CartBeanService service;

//	取得所有
	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public List<CartBean> getAllCarts() {
		return service.getAllCartBean();
	}

//	取得指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public CartBean getCartBeanById(@PathVariable long id) {
		CartBean cartBean = service.getCartBeanById(id);
		return cartBean;
	}

//	刪除指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public void removeCartBean(@PathVariable long id) {
		System.out.println("DeleteNum=>"+id);
		service.removeCartBean(id);
	}
	
//	刪除全部
	@RequestMapping(value = "/all", method = RequestMethod.DELETE)
	public void removeAllCartBean() {
		service.removeAllCartBean();
	}

//	新增
	@RequestMapping(value = "/all", method = RequestMethod.POST)
	public String createCart(@RequestBody CartBean bean) {
		service.saveOrUpdateCartBean(bean);
		return bean.toString();
	}
	
//	修改 
	@RequestMapping(value = "/{id}",method=RequestMethod.PUT)
	public CartBean modifyCart(@PathVariable("id")Long id,@RequestBody CartBean bean) {
		bean.setId(id);
		return service.updateCartBean(bean);
	}
	
//	修改 
//	@RequestMapping(value = "/{name}",method=RequestMethod.PUT)
//	public CartBean modifyAmount(@PathVariable("name")String name,@RequestBody CartBean bean) {
//		int num=0;
//		bean.setAmount(num++);
//		return service.updateCartBean(bean);
//	}
	
//	比對是否存在
	@RequestMapping(value = "/{name}", method = RequestMethod.POST)
	public Boolean compareProductBeanByName(@PathVariable String name) {
		Boolean exist =false;
		
		//將現有購物車資料查出
		List<CartBean> allCartList = service.getAllCartBean();
		
		//將每筆資料與目前想加入的商品名稱比對
		for (CartBean cartBean : allCartList) {
			String cartName = cartBean.getName();
			
			//如果相同代表已存在購物車了
			if(name.equals(cartName)) {
				System.out.println("商品："+name+"已存在");
				exist=true;		
			}	
		}
		return exist;
//		
//		System.out.println("DeleteNum=>"+id);
//		service.removeCustomerBean(id);
	}
}

```
# customerbeancontroller
```
package com.ctbcbank.demo.lab.controller.rest;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ctbcbank.demo.lab.bean.CustomerBean;
import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.service.CustomerBeanService;
import com.ctbcbank.demo.lab.service.ProductBeanService;

import lombok.extern.slf4j.Slf4j;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/api/customer")
public class CustomerBeanController {
	@Autowired
	private CustomerBeanService service;
	@Autowired
	private ProductBeanService PBservice;

//	取得所有帳戶
	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public List<CustomerBean> getAllCustomers() {
		return service.getAllCustomerBean();
	}

//	取得指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public CustomerBean getCustomerBeanById(@PathVariable long id) {
		CustomerBean customerBean = service.getCustomerBeanById(id);
		return customerBean;
	}

//	刪除指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public void removeCustomerBean(@PathVariable long id) {
		System.out.println("DeleteNum=>"+id);
		service.removeCustomerBean(id);
	}
	

//	新增
	@RequestMapping(value = "/all", method = RequestMethod.POST)
	public String createCustomer(@RequestBody CustomerBean bean) {
		service.saveOrUpdateCustomerBean(bean);
		return bean.toString();
	}
	
//	修改 
	@RequestMapping(value = "/{id}",method=RequestMethod.PUT)
	public CustomerBean modifyCustomer(@PathVariable("id")Long id,@RequestBody CustomerBean bean) {
		bean.setId(id);
		return service.updateCustomerBean(bean);
	}
	
//	比對是否存在
	@RequestMapping(value = "/{name}", method = RequestMethod.POST)
	public Boolean compareCustomerBeanByName(@PathVariable String name) {
		Boolean exist =false;
		
		//將現有帳戶資料查出
		List<CustomerBean> allCustomerList = service.getAllCustomerBean();
		
		//將每筆資料與目前想加入的帳號比對
		for (CustomerBean customerBean : allCustomerList) {
			String customerName = customerBean.getName();
			
			//如果相同代表帳戶已存在
			if(name.equals(customerName)) {
				System.out.println("使用者："+name+"已存在");
				exist=true;		
			}	
		}
		return exist;
//		
//		System.out.println("DeleteNum=>"+id);
//		service.removeCustomerBean(id);
	}
	
//	新增
	@RequestMapping(value = "/{customer_id}/{product_id}", method = RequestMethod.POST)
	public String addProduct(@PathVariable("customer_id")Long customer_id,@PathVariable("product_id")Long product_id) {
		CustomerBean c1 = service.getCustomerBeanById(customer_id);
		ProductBean p1 = PBservice.getProductBeanById(product_id);
		List<ProductBean> products = new ArrayList<ProductBean>();
		products.add(p1);
		c1.setProducts(products);
		c1.getProducts().add(p1);
		service.saveOrUpdateCustomerBean(c1);
		return c1.toString();
	}
}

```
#  productbeancontroller
```
package com.ctbcbank.demo.lab.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.bean.ProductCategoryBean;
import com.ctbcbank.demo.lab.repository.ProductBeanRepository;
import com.ctbcbank.demo.lab.service.ProductBeanService;
import com.ctbcbank.demo.lab.service.ProductCategeryBeanService;

import lombok.extern.slf4j.Slf4j;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/api/product")
public class ProductBeanController {
	@Autowired
	private ProductBeanService service;
	@Autowired
	private ProductCategeryBeanService categoryService;
	@Autowired
	private ProductBeanRepository repository;

//	取得所有
	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public List<ProductBean> getAllProducts() {
		return service.getAllProductBean();
	}

//	取得指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ProductBean getProductBeanById(@PathVariable long id) {
		ProductBean productBean = service.getProductBeanById(id);
		return productBean;
	}

//	刪除指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public void removeProductBean(@PathVariable long id) {

		service.removeProductBean(id);
	}

////	新增
//	@RequestMapping(value = "/all", method = RequestMethod.POST)
//	public String createProduct(@RequestBody ProductBean bean) {
//		service.saveOrUpdateProductBean(bean);
//		
//		return bean.toString();
//	}

//	新增
	@RequestMapping(value = "/all/{id}", method = RequestMethod.POST)
	public String createProduct(@RequestBody ProductBean bean, @PathVariable("id") Long id) {
		bean.setProductCategory(categoryService.getProductCategoryBeanById(id));
		service.saveOrUpdateProductBean(bean);
		return bean.toString();
	}

//	修改 
	@RequestMapping(value = "/{id}/{cate_id}", method = RequestMethod.PUT)
	public ProductBean modifyProduct(@PathVariable("id") Long id, @PathVariable("cate_id") Long cate_id,
			@RequestBody ProductBean bean) {
		bean.setProductCategory(categoryService.getProductCategoryBeanById(cate_id));
		bean.setId(id);
		return service.saveOrUpdateProductBean(bean);
	}

//	取得指定名稱
//	@RequestMapping(value = "/{name}", method = RequestMethod.GET)
//	public List<ProductBean> getProductBeanByName(@PathVariable String name) {
//		return repository.findByTitleContainingIgnoreCase(name);
//	}
}

```
# productCategoryBeanController
```
package com.ctbcbank.demo.lab.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.bean.ProductCategoryBean;
import com.ctbcbank.demo.lab.service.ProductCategeryBeanService;

import lombok.extern.slf4j.Slf4j;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/api/productCategory")
public class ProductCategoryBeanController {
	@Autowired
	private ProductCategeryBeanService service;

//	取得所有
	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public List<ProductCategoryBean> getAllProducts() {
		return service.getAllProductCategoryBean();
	}

//	取得指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ProductCategoryBean getProductCategeryBeanById(@PathVariable long id) {
		ProductCategoryBean productCategoryBean = service.getProductCategoryBeanById(id);
		return productCategoryBean;
	}

//	刪除指定id
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public void removeProductCategeryBean(@PathVariable long id) {
		System.out.println("DeleteNum=>" + id);
		service.removeProductCategoryBean(id);
	}

//	新增
	@RequestMapping(value = "/all", method = RequestMethod.POST)
	public String createProductCategery(@RequestBody ProductCategoryBean bean) {
		service.saveOrUpdateProductCategoryBean(bean);
		return bean.toString();
	}	
	

//	修改 
	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	public ProductCategoryBean modifyProductCategory(@PathVariable("id") Long id, @RequestBody ProductCategoryBean bean) {
		bean.setId(id);
		return service.updateProductCategoryBean(bean);
	}
}


```

# addProductCart
```
package com.ctbcbank.demo.lab.runner;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.ctbcbank.demo.lab.bean.CustomerBean;
import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.repository.CustomerBeanRepository;
import com.ctbcbank.demo.lab.repository.ProductBeanRepository;

import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
@Order(6)
public class addProductCart implements CommandLineRunner {
	@Autowired
	CustomerBeanRepository repository;
	@Autowired
	ProductBeanRepository PBrepository;
	@Override
	public void run(String... args) throws Exception {
		log.info("test1");
		CustomerBean c1=repository.findById(11l).get();
		ProductBean p1=PBrepository.findById(1l).get();
		ProductBean p2=PBrepository.findById(2l).get();
		List<ProductBean> test = new ArrayList<ProductBean>();
		test.add(p2);
		c1.setProducts(test);
		c1.getProducts().add(p1);
		log.info("test2");
		repository.save(c1);
	}

}

```
# addproducttocategory
```
package com.ctbcbank.demo.lab.runner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.bean.ProductCategoryBean;
import com.ctbcbank.demo.lab.repository.ProductBeanRepository;
import com.ctbcbank.demo.lab.repository.ProductCategoryBeanRepository;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@Order(5)
public class addProductToCategory implements CommandLineRunner{
	@Autowired
	ProductCategoryBeanRepository repositoryC;
	@Autowired
	ProductBeanRepository repository;

	@Override
	public void run(String... args) throws Exception {
		ProductBean product = null;
		ProductBean product2 = null;
		ProductBean product3 = null;
		ProductBean product4 = null;
		ProductBean product5 = null;
		ProductBean product6 = null;
		ProductBean product7 = null;
		ProductBean product8 = null;
		ProductCategoryBean productCategory = null;
		ProductCategoryBean productCategory2 = null;
		try
		{
			product = repository.findById(1l).get();
			product2 = repository.findById(2l).get();
			product3 = repository.findById(3l).get();
			product4 = repository.findById(4l).get();
			
			product5 = repository.findById(5l).get();
			product6 = repository.findById(6l).get();
			product7 = repository.findById(7l).get();
			product8 = repository.findById(8l).get();
			log.info("[V]get object sucess");
		}catch(
		Exception e)
		{
			log.info("[X]get object fail");
		}
		
		try
		{
			productCategory = repositoryC.findById(10l).get();
			productCategory2 = repositoryC.findById(9l).get();
			log.info("[V]get object sucess");
		}catch(
		Exception e)
		{
			log.info("[X]get object fail");
		}
		try {
			product.setProductCategory(productCategory);
			product2.setProductCategory(productCategory);
			product3.setProductCategory(productCategory);
			product4.setProductCategory(productCategory);
			
			product5.setProductCategory(productCategory2);
			product6.setProductCategory(productCategory2);
			product7.setProductCategory(productCategory2);
			product8.setProductCategory(productCategory2);
			
			repository.save(product);
			repository.save(product2);
			repository.save(product3);
			repository.save(product4);
			
			repository.save(product5);
			repository.save(product6);
			repository.save(product7);
			repository.save(product8);
			log.info("[V]get object sucess");
			
		}catch (Exception e) {
			log.info("[X]get object fail");
		}
	}

	
}

```
# cartbeanrunner
```
package com.ctbcbank.demo.lab.runner;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.ctbcbank.demo.lab.bean.CartBean;
import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.bean.ProductCategoryBean;
import com.ctbcbank.demo.lab.repository.CartBeanRepository;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@Order(3)
public class CartBeanRunner implements CommandLineRunner {
	@Autowired
	CartBeanRepository repository;

	@Override
	public void run(String... args) throws Exception {
		insertData();
		
	}

	private void insertData() {
		
		ProductCategoryBean pc1 = new ProductCategoryBean();
		pc1.setName("cate1");
		ProductCategoryBean pc2 = new ProductCategoryBean();
		pc2.setName("cate2");
		ProductCategoryBean pc3 = new ProductCategoryBean();
		pc3.setName("cate3");
		

		
	}
}


```
# customerbeanrunner
```
package com.ctbcbank.demo.lab.runner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.ctbcbank.demo.lab.bean.CartBean;
import com.ctbcbank.demo.lab.bean.CustomerBean;
import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.repository.CustomerBeanRepository;
import com.ctbcbank.demo.lab.repository.ProductBeanRepository;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@Order(4)
public class CustomerBeanRunner implements CommandLineRunner {
	@Autowired
	CustomerBeanRepository repository;
	@Autowired
	ProductBeanRepository PBrepository;
	@Override
	public void run(String... args) throws Exception {
		insertData();
		
	}

	private void insertData() {

		CustomerBean c1 = new CustomerBean("Z00053015","12345");
		CustomerBean c2 = new CustomerBean("name2","pass2");
		CustomerBean c3 = new CustomerBean("name3","pass3");	
		CustomerBean[] CustomerBean = { c1, c2, c3 };
		for (CustomerBean c : CustomerBean) {
			
			repository.save(c);	
		}
	}
	}

```
# productbeanrunner
```
package com.ctbcbank.demo.lab.runner;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.ctbcbank.demo.lab.bean.CartBean;
import com.ctbcbank.demo.lab.bean.CustomerBean;
import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.bean.ProductCategoryBean;
import com.ctbcbank.demo.lab.repository.CartBeanRepository;
import com.ctbcbank.demo.lab.repository.ProductBeanRepository;
import com.ctbcbank.demo.lab.repository.ProductCategoryBeanRepository;

import lombok.extern.slf4j.Slf4j;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
@Order(1)
public class ProductBeanRunner implements CommandLineRunner {
	@Autowired
	ProductBeanRepository repository;
	@Autowired
	ProductCategoryBeanRepository categoryRepository;
	@Autowired
	CartBeanRepository cartRepository;

	@Override
	public void run(String... args) throws Exception {

		insertData();

	}

	private void insertData() {
		ProductBean p1 = new ProductBean("Iphone 14 Pro Max", 39688,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-14-pro-finish-select-202209-6-7inch-silver?wid=5120&hei=2880&fmt=p-jpg&qlt=80&.v=1663703841892", "256GB");
		ProductBean p2 = new ProductBean("Iphone 14 Pro", 34900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-14-pro-finish-select-202209-6-1inch-spaceblack?wid=5120&hei=2880&fmt=p-jpg&qlt=80&.v=1663703840510", "128GB");
		ProductBean p3 = new ProductBean("Iphone 14 Plus", 31900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-14-finish-select-202209-6-7inch-purple?wid=5120&hei=2880&fmt=p-jpg&qlt=80&.v=1661027938735", "256GB");
		ProductBean p4 = new ProductBean("Iphone 14 ", 27900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/iphone-14-finish-select-202209-6-1inch-midnight?wid=5120&hei=2880&fmt=p-jpg&qlt=80&.v=1661026579503", "128GB");
		repository.save(p1);
		repository.save(p2);
		repository.save(p3);
		repository.save(p4);
		
		
		ProductBean p5 = new ProductBean("iPad Pro", 27900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/ipad-pro-finish-select-202212-11inch-space-gray-wifi?wid=5120&hei=2880&fmt=p-jpg&qlt=95&.v=1670865951347", "128GB");
		ProductBean p6 = new ProductBean("iPad Air 5", 19900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/ipad-air-finish-select-gallery-202211-space-gray-wifi?wid=5120&hei=2880&fmt=p-jpg&qlt=95&.v=1670948364698", "64GB");
		ProductBean p7 = new ProductBean("iPad 10", 14900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/ipad-10th-gen-finish-select-202212-blue-wifi?wid=5120&hei=2880&fmt=p-jpg&qlt=95&.v=1670856033679", "64GB");
		ProductBean p8 = new ProductBean("iPad mini", 16900,
				"https://store.storeimages.cdn-apple.com/8756/as-images.apple.com/is/ipad-mini-storage-select-202207-purple-wifi?wid=5120&hei=2880&fmt=p-jpg&qlt=95&.v=1670950640688", "64GB");
		repository.save(p5);
		repository.save(p6);
		repository.save(p7);
		repository.save(p8);
		
		
	}
}
```
# productCategorybeanrunner
```
package com.ctbcbank.demo.lab.runner;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.ctbcbank.demo.lab.bean.ProductBean;
import com.ctbcbank.demo.lab.bean.ProductCategoryBean;
import com.ctbcbank.demo.lab.repository.ProductCategoryBeanRepository;

import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
@Order(2)
@SpringBootApplication
public class ProductCategoryBeanRunner implements CommandLineRunner {
	@Autowired
	ProductCategoryBeanRepository repository;

	@Override
	public void run(String... args) throws Exception {
		insertData();

	}
	private void insertData() {
		ProductCategoryBean pc1 = new ProductCategoryBean();
		pc1.setName("Ipad");
		ProductCategoryBean pc2 = new ProductCategoryBean();
		pc2.setName("Iphone");
//		ProductCategoryBean pc3 = new ProductCategoryBean();
//		pc3.setName("cate3");
		repository.save(pc1);
		repository.save(pc2);
//		repository.save(pc3);
		log.info("ProductsCategoryBean:{}",pc1);
		log.info("ProductsCategoryBean:{}",pc2);
//		log.info("ProductsCategoryBean:{}",pc3);
	}
}

```