📄 70398698d01d001e1672a24ec0ef4ea6
字号:
package com.cric.onlineshopclothes.dao;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cric.onlineshopclothes.javabean.Category;
import com.cric.onlineshopclothes.javabean.Product;
import com.cric.onlineshopclothes.util.DBUtils;
import com.cric.onlineshopclothes.util.UploadBeanUTF;
public class ProductDAO {
public Category addCategoryParam(HttpServletRequest request, HttpServletResponse response){
Category category=new Category();
String categoryName=request.getParameter("categoryName");
String categoryState=request.getParameter("categoryState");
SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String ctime=format.format(new Date());
category.setCategoryName(categoryName==null?"":categoryName);
category.setCategoryState(categoryState);
category.setUpdateTime(ctime);
//category.setCategoryState(categoryState==null?"":categoryState);
return category;
}
public boolean insertCategory(Category category){
boolean flag=false;
String sqlStr="insert into category values('"+category.getCategoryName()+"','"+category.getCategoryState()+"','"+category.getUpdateTime()+"')";
System.out.println(sqlStr);
DBUtils db=new DBUtils();
flag=db.excuteUpdate(sqlStr);
db.closeStmt();
db.closeConnection();
System.out.println(flag);
return flag;
}
public List getAllCategory(){
DBUtils db=new DBUtils();
List list=new ArrayList();
String sql="select * from category";
try{
ResultSet rs=db.excuteQuery(sql);
while(rs.next()){
Category category=new Category();
category.setCategoryId(rs.getInt("categoryId"));
category.setCategoryName(rs.getString("categoryName"));
category.setCategoryState(rs.getString("categoryState"));
category.setUpdateTime(rs.getString("updateTime"));
list.add(category);
}
}catch(Exception e){
e.printStackTrace();
}finally{
db.closeConnection();
}
return list;
}
public List getCategoryByUsername(String categoryName){
DBUtils db=new DBUtils();
List list=new ArrayList();
String sql="select * from category where categoryName like '%"+categoryName+"%'";
try{
ResultSet rs=db.excuteQuery(sql);
while(rs.next()){
Category category=new Category();
category.setCategoryId(rs.getInt("categoryId"));
category.setCategoryName(rs.getString("categoryName"));
category.setCategoryState(rs.getString("categoryState"));
category.setUpdateTime(rs.getString("updateTime"));
list.add(category);
}
}catch(Exception e){
e.printStackTrace();
}finally{
db.closeConnection();
}
return list;
}
public List getProductCategory(){
DBUtils db=new DBUtils();
List list=new ArrayList();
String sql="select * from category" ;
try{
ResultSet rs=db.excuteQuery(sql);
while(rs.next()){
Category category=new Category();
category.setCategoryId(rs.getInt("categoryId"));
category.setCategoryName(rs.getString("categoryName"));
category.setCategoryState(rs.getString("categoryState"));
category.setUpdateTime(rs.getString("updateTime"));
list.add(category);
}
}catch(Exception e){
e.printStackTrace();
}finally{
db.closeConnection();
}
return list;
}
public Product getProductParam(HttpServletRequest request, HttpServletResponse response){
UploadBeanUTF fileBean=new UploadBeanUTF();
String filename="";
try{
fileBean.setObjectPath("E:\\Workspaces\\OnlineShopClothes\\WebRoot");
//fileBean.setObjectFileName("1.jpg");
//fileBean.setSize(10000*1024);
fileBean.setSourceFile(request);
filename=fileBean.getNewFileName();
}catch(Exception e){e.printStackTrace();}
String categoryId=fileBean.getFieldValue("categoryId");
String productName=fileBean.getFieldValue("PName");
String productDetail=fileBean.getFieldValue(" Detail");
String productInPrice=fileBean.getFieldValue("InPrice");
String productOutPrice=fileBean.getFieldValue("OutPrice");
String productAmount=fileBean.getFieldValue("productAmount");
String productState=fileBean.getFieldValue("State");
SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String ctime=format.format(new Date());
String Hot=fileBean.getFieldValue("Hot");
String SaledAmount=fileBean.getFieldValue("SaledAmount");
String productPic=filename;
Product pro=new Product();
pro.setCategoryId(categoryId==null?0:Integer.parseInt(categoryId));
pro.getPName(productName==null?"":productName);
pro.setProductDetail(productDetail==null?"":productDetail);
pro.setProductPrice(productPrice==null?0:Float.parseFloat(productPrice));
pro.setProductAmount(productAmount==null?0:Integer.parseInt(productAmount));
pro.setProductState(productState==null?0:Integer.parseInt(productState));
pro.setProductPic(productPic==null?"":productPic);
return pro;
}
public boolean insertProduct(Product product){
boolean flag=false;
DBUtils db=new DBUtils();
String sqlStr="insert into product(" +
"categoryId," +
"PName," +
"Detail," +
"InPrice," +
"OutPrice," +
"Amount," +
"Picture,"+
"State," +
"ProductTime," +
" Hot," +
"SaledAmount) " +
"values('"+
+product.getPName()+"'," +
"'"+product.getDetail()+"',"
+product.getInPrice()+","
+product.getOutPrice()+",'"
+product.getAmount()+"',"
+product.getPicture()+"',"
+product.getState()+"',"
+product.getProductTime()+"',"
+product.getHot()+"',"
+product.getSaledAmount()+")";
flag=db.excuteUpdate(sqlStr);
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -