allfoodsbean.java
来自「订餐系统」· Java 代码 · 共 60 行
JAVA
60 行
package Entities;
import java.sql.*;
import java.util.*;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;
import Dao.*;
public class allFoodsBean {
private Connection con;
private String sql;
//返回FoodBean列表
public List getFoods()
{
List foods = new ArrayList();
//获取书籍列表
try
{
SQLCommandBean sqlCommandBean = new SQLCommandBean();
con = ConnectionManage.getConnection();
sql = "select foodID,foodName,remark,foodPrice,description,foodImage from foodInfo";
sqlCommandBean.setConn(con);
sqlCommandBean.setSqlValue(sql);
Result result = sqlCommandBean.executeQuery();
if(result == null || result.getRowCount() == 0)
{
//没有查出Book
System.out.print("没有记录");
}
else
{
int rowCount = result.getRowCount();
//读取行数据
for(int i = 0; i < rowCount; i ++)
{
Map row = result.getRows()[i];
FoodBean food = new FoodBean();
food.setFoodID((String)row.get("foodID"));
food.setFoodName((String)row.get("foodName"));
food.setRemark((String)row.get("remark"));
food.setFoodPrice(Double.parseDouble(row.get("foodPrice").toString()));
//food.setFoodPrice(((Double) row.get("foodPrice")).doubleValue());
food.setDescription((String)row.get("description"));
food.setFoodImage((String)row.get("foodImage"));
foods.add(food);
}
}
}catch(Exception ex)
{
ex.printStackTrace();
}
return foods;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?