⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fooddao.java

📁 MVC设计+jsp+servlet+sqlserver开发
💻 JAVA
字号:
package com.accp.fan.dao;

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

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.accp.fan.db.Basedao;
import com.accp.fan.entity.Food;

public class Fooddao extends Basedao {

	public Fooddao() throws ClassNotFoundException, SQLException {
	
	}
	
	//全部查询食物
	public List getAllFood() throws SQLException, ClassNotFoundException
	{
		List list=new ArrayList();
		String sql="select * from foodInfo";
		/*
		 * 这个类是dbUtil中定义的类,继承一个接口,实现这个接口中的方法,
		 * 用于将封装的bean转换成list,
		 * 但参数需要指明是按照哪个bean转换,
		 * 这样就隐藏了接口,不需要自己去定义
		 */
		BeanListHandler bh=new BeanListHandler(Food.class);
		list=super.executeQuery(sql, bh);
		return list;
	}
	
	//条件查询
	public Food getFoodById(String foodID) throws SQLException, ClassNotFoundException
	{
		String sql="select * from foodInfo where foodID=?";
		/*
		 * 这个类是dbUtil中定义的类,继承一个接口,实现这个接口中的方法,
		 * 用于将封装的bean转换成list,
		 * 但参数需要指明是按照哪个bean转换,
		 * 这样就隐藏了接口,不需要自己去定义
		 * 重写了上面的查询方法,并提供了不同的参数,
		 */
		BeanListHandler bh=new BeanListHandler(Food.class);
		Object[] args=new Object[]{foodID}; 
		List list=super.executeQuery(sql, args, bh);
		Food food=(Food) list.get(0);
		return food;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -