📄 test.java
字号:
package com.witbridge.test;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.struts.action.ActionMessage;
import com.witbridge.netstore.dao.impl.CustomerDaoImpl;
import com.witbridge.netstore.dao.impl.ItemDaoImpl;
import com.witbridge.netstore.dao.impl.LineItemDaoImpl;
import com.witbridge.netstore.dao.impl.OderDaoImpl;
import com.witbridge.netstore.factory.MyDaoImpl;
import com.witbridge.netstore.model.Customers;
import com.witbridge.netstore.model.Items;
import com.witbridge.netstore.model.LineItem;
import com.witbridge.netstore.model.Oder;
import com.witbridge.netstore.service.NetStoreService;
import com.witbridge.netstore.service.NetStoreServiceImpl;
import com.witbridge.netstore.util.DBUtil;
public class Test {
static Connection conn=null;
public static void main(String[] args) throws SQLException{
Test test=new Test();
// testCostomerDao();
// testItemDao();
// testLineItem();
// testOderDao();
test.testNetStoreServiceImpl();
}
// public static void testCostomerDao(){
// CustomerDaoImpl cdi=MyDaoImpl.getCustomerDaoImpl();
// Customers customer=cdi.getCustomer("zhang@", "223");
// if(customer!=null){
// System.out.println(customer);
//
// }else{
// System.out.print("fail");
// }
// Customers customer=new Customers();
// customer.setCustomerId(112);
// customer.setCustomerName("zhang");
// customer.setEmail("zhang@126.com");
// customer.setPassword("123");
// int i=cdi.updateCustomer(customer);
// if(i>0){
// System.out.println("update customer succes");
// }
// int i=cdi.addCustomer(customer);
// if(i>0){System.out.println("1、add customer succes");}
//
// int j=cdi.deleteCustomer(112);
// if(j>0){System.out.println("2、delect customer succes");}
//
// customer=cdi.getCustomer("tom@yahoo.com","1234");
// if(customer!=null){
// System.out.println("3、get customer succes");
// }
// List<Customers> customers=new ArrayList();
// customers=cdi.getAllCustomers();
// if(customers!=null){
// System.out.println("4、get List<Customers> succes");
// }
// }
// public static void testItemDao(){
// Items item=new Items();
// ItemDaoImpl idm=MyDaoImpl.getItemDaoImpl();
// List<Items> items=idm.getAllItems();
//
// for (Items items2 : items) {
// System.out.println(items2.getItemId());
// }
// Iterator it=items.iterator();
// while(it.hasNext()){
// System.out.println(it.next());
// }
// if(items!=null){
// System.out.println("5、get List<Items> succes");
// }
// item=idm.getItem(112);
// if(item!=null){
// System.out.println("6、get item succes");
// }
//
// item.setItemId(120);
// item.setItemName("hello");
// item.setModelnumber("hello");
// item.setDescription("hello");
// item.setFeatrue("hello");
// item.setSmallimage("");
// item.setLageimage("");
// item.setBaseprice(0.0);
// int i=idm.addItem(item);
// if(i>0){
// System.out.println("7、add item succes");
// }
//
// int j=idm.deleteItem(120);
// if(j>0){
// System.out.println("8、delete item succes");
// }
//}
// public static void testLineItem() throws SQLException{
// LineItemDaoImpl ldm=MyDaoImpl.getLineItemDaoImpl();
// List<LineItem> lineItems=new ArrayList();
// Customers customer=new Customers();
// LineItem lineItem=new LineItem();
// Oder oder=new Oder("101",10.0,customer,lineItems);
// Items item=new Items(110,"","","","","","",10.0);
// Oder oder=new Oder();
// Items item=new Items();
// Connection con=DBUtil.getIstance().getConn();
// oder.setOdernumber("101");
// item.setItemId(110);
//
// lineItem.setOder(oder);
// lineItem.setItem(item);
// lineItem.setQuantity(12);
// int i=ldm.addLineItem(con, lineItem);
// if(i>0){
// System.out.println("9、add lineItem succes");
// }
//
// ldm.deleteLineItem(item,oder);
// }
// public static void testOderDao() throws SQLException{
// OderDaoImpl odm=MyDaoImpl.getOderDaoImpl();
// Customers customer=new Customers();
// Connection con=DBUtil.getIstance().getConn();
// Oder oder = new Oder();
//
// customer.setCustomerId(1);
//
// oder.setAddress("");
// oder.setCity("");
// oder.setCustomer(customer);
// oder.setOdernumber("102");
// oder.setPhone("");
// oder.setPostalCode("");
// oder.setPrice(2543.0);
// oder.setState("");
//
// int i = odm.addOder(con, oder);
// if(i>0){
// System.out.println("10、add oder succes");
// }
//
// odm.deleteOder(oder);
// }
//
public NetStoreService getNetStoreService(){
return new NetStoreServiceImpl();
}
public void testNetStoreServiceImpl() throws SQLException{
NetStoreService service=getNetStoreService();
conn=DBUtil.getIstance().getConn();
NetStoreServiceImpl nsi=MyDaoImpl.getNetStoreServiceImpl();
Customers customer=service.getCustomerById(new Long(7));
List<LineItem> lineItems=new ArrayList();
Oder order=new Oder();
Items item=service.getItemById(new Long(110));
LineItem lineItem = new LineItem();
lineItem.setBasePrice(item.getBaseprice());
lineItem.setItem(item);
lineItems.add(lineItem);
order.setAddress("");
order.setCity("");
order.setCustomer(customer);
order.setLineItems(lineItems);
order.setOdernumber("102");
order.setPhone("");
order.setPostalCode("");
order.setPrice(1.0);
order.setState("");
lineItem.setOder(order);
lineItem.setQuantity(3);
nsi.saveOrder(order);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -