src/com/demo/dao/impl/ClothesDaoImpl.java

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.demo.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.demo.utils.JdbcUtils;
import com.demo.dao.ClothesDao;
import com.demo.model.Clothes;

/**
 * dao层实现-对数据库:商品表的操作
 * @author shao
 */
public class ClothesDaoImpl implements ClothesDao {
	
	/** (non-Javadoc)
	 * @see com.demo.dao.ClothesDao#add(com.demo.model.Clothes)
	 */
	@Override
	public void add(Clothes clothes){
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource());// JDBC的调用者,数据库操作类,DBUtils工具,参数为c3p0连接池
			String sql = "insert into clothes(id,name,brand,price,image,description,category_id) values(?,?,?,?,?,?,?)";// SQL语句
			Object params[] = {clothes.getId(), clothes.getName()
					, clothes.getBrand(), clothes.getPrice()
					, clothes.getImage(), clothes.getDescription()
					, clothes.getCategoryId()};// 多个参数封装为对象数组
			runner.update(sql, params);// 执行SQL语句
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	/** (non-Javadoc)
	 * @see com.demo.dao.ClothesDao#find(java.lang.String)
	 */
	@Override
	public Clothes find(String id){
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource());// JDBC的调用者,数据库操作类,DBUtils工具,参数为c3p0连接池
			String sql = "select * from clothes where id=?";// SQL语句
			return (Clothes)runner.query(sql, id, new BeanHandler(Clothes.class));// 执行SQL语句,并使用BeanHandler工具将结果转为POJO对象
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	/** (non-Javadoc)
	 * @see com.demo.dao.ClothesDao#getPageData(int, int)
	 */
	@Override
	public List<Clothes> getPageData(int startIndex, int pageSize){
		try {
后面还有 58 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。