|
@@ -0,0 +1,74 @@
|
|
|
|
+package cn.dao.impl;
|
|
|
|
+
|
|
|
|
+import cn.dao.ProductDao;
|
|
|
|
+import cn.domain.Product;
|
|
|
|
+import cn.util.JDBCUtils;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+public class ProductDaoImpl implements ProductDao {
|
|
|
|
+ private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
|
|
|
|
+ @Override
|
|
|
|
+ public List<Product> findProduct() throws Exception {
|
|
|
|
+ String sql = "select * from products";
|
|
|
|
+// System.out.println(template.query(sql,new BeanPropertyRowMapper<Product>(Product.class)).toString());
|
|
|
|
+ return template.query(sql,new BeanPropertyRowMapper<Product>(Product.class));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Product findProductById(String mid) throws Exception {
|
|
|
|
+ String sql = "select * from products where mid = ?";
|
|
|
|
+ Product product = template.queryForObject(sql,new BeanPropertyRowMapper<Product>(Product.class),mid);
|
|
|
|
+ return product;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Product> findProductByScompany(String scompany) throws Exception {
|
|
|
|
+ try{
|
|
|
|
+ String sql = "select * from products where scompany = ?";
|
|
|
|
+ List<Product> products = template.query(sql,new BeanPropertyRowMapper<Product>(Product.class),scompany);
|
|
|
|
+ return products;
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.getMessage();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void addProduct(Product product) throws Exception {
|
|
|
|
+ String mid = product.getMid();
|
|
|
|
+ int id = product.getId();
|
|
|
|
+ String name = product.getName();
|
|
|
|
+ double price = product.getPrice();
|
|
|
|
+ String detail = product.getDetail();
|
|
|
|
+ String scompany = product.getScompany();
|
|
|
|
+ String img = product.getImg();
|
|
|
|
+ String sql = "insert into products values(?,?,?,?,?,?,?)";
|
|
|
|
+ template.update(sql,mid,id,name,price,detail,scompany,img);
|
|
|
|
+ System.out.println(template.update(sql,mid,id,name,price,detail,scompany,img));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void deleteProduct(String mid) throws Exception {
|
|
|
|
+ String sql = "delete from products where mid=?";
|
|
|
|
+ template.update(sql,mid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void updateProduct(Product product) throws Exception {
|
|
|
|
+ String sql = "update products set id=?,name=?,price=?,detail=?,scompany=?,img=? where mid=?";
|
|
|
|
+ int id = product.getId();
|
|
|
|
+ String name = product.getName();
|
|
|
|
+ double price = product.getPrice();
|
|
|
|
+ String detail = product.getDetail();
|
|
|
|
+ String scompany = product.getScompany();
|
|
|
|
+ String img = product.getImg();
|
|
|
|
+ String mid = product.getMid();
|
|
|
|
+ System.out.println(template.update(sql,id,name,price,detail,scompany,img,mid));
|
|
|
|
+ template.update(sql,id,name,price,detail,scompany,img,mid);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|