how2j.cn

步骤 1 : ProductImageDAO.java   
步骤 2 : 基本的CRUD   
步骤 3 : 产品图片分类属性   
步骤 4 : 非CRUD方法   

步骤 1 :

ProductImageDAO.java

edit edit
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package tmall.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import tmall.bean.Product; import tmall.bean.ProductImage; import tmall.util.DBUtil; public class ProductImageDAO { public static final String type_single = "type_single"; public static final String type_detail = "type_detail"; public int getTotal() { int total = 0; try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { String sql = "select count(*) from ProductImage"; ResultSet rs = s.executeQuery(sql); while (rs.next()) { total = rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } return total; } public void add(ProductImage bean) { String sql = "insert into ProductImage values(null,?,?)"; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setInt(1, bean.getProduct().getId()); ps.setString(2, bean.getType()); ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { int id = rs.getInt(1); bean.setId(id); } } catch (SQLException e) { e.printStackTrace(); } } public void update(ProductImage bean) { } public void delete(int id) { try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { String sql = "delete from ProductImage where id = " + id; s.execute(sql); } catch (SQLException e) { e.printStackTrace(); } } public ProductImage get(int id) { ProductImage bean = new ProductImage(); try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) { String sql = "select * from ProductImage where id = " + id; ResultSet rs = s.executeQuery(sql); if (rs.next()) { int pid = rs.getInt("pid"); String type = rs.getString("type"); Product product = new ProductDAO().get(pid); bean.setProduct(product); bean.setType(type); bean.setId(id); } } catch (SQLException e) { e.printStackTrace(); } return bean; } public List<ProductImage> list(Product p, String type) { return list(p, type,0, Short.MAX_VALUE); } public List<ProductImage> list(Product p, String type, int start, int count) { List<ProductImage> beans = new ArrayList<ProductImage>(); String sql = "select * from ProductImage where pid =? and type =? order by id desc limit ?,? "; try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setInt(1, p.getId()); ps.setString(2, type); ps.setInt(3, start); ps.setInt(4, count); ResultSet rs = ps.executeQuery(); while (rs.next()) { ProductImage bean = new ProductImage(); int id = rs.getInt(1); bean.setProduct(p); bean.setType(type); bean.setId(id); beans.add(bean); } } catch (SQLException e) { e.printStackTrace(); } return beans; } }
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
步骤 3 :

产品图片分类属性

edit edit
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的J2EE模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE一整套技术栈, 从无到有涵盖全部147个知识点,475个开发步骤, 充实J2EE项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-天猫整站J2EE-ProductImageDAO 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 982790551
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图