关于增删改查方法中 public后的 返回值类型
来源:互联网 发布:免费瓷砖设计软件 编辑:程序博客网 时间:2024/05/16 07:14
如一下代码中 public List<Product> findProduct(int start, int pageSize) 。。。{ ...return XX;} XX的类型一定要和前面的返回值类型一致。
public List<Product> findProduct(int start, int pageSize)
throws SQLException {
QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select * from product limit ?,?";
return qr.query(sql, new BeanListHandler<Product>(Product.class),
start, pageSize);
}
// 总数
public int findTotalCount() throws SQLException {
QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select count(*) from product";
return ((Long) qr.query(sql, new ScalarHandler())).intValue();
}
// 保存
public int addProduct(Product product) throws SQLException {
String sql = "insert into Product values(?,?,?,?,?,?,?,?,?,?)";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
// 返回值 int代表影响的行数
return runner.update(sql, product.getPid(), product.getPname(), product
.getMarket_price(), product.getShop_price(), product
.getPimage(), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(product.getPdate()), product.getIs_hot(), product
.getPdesc(), product.getPflag(), product.getCid());
}
// 删除数据库的记录
public int deleteProduct(String pid) throws SQLException {
String sql = "delete from product where pid=?";
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
return runner.update(sql, pid);
}
// 查询单个product对象
public Product findProductByPid(String pid) throws SQLException {
String sql = "select * from product where pid=?";
QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
Product product = qr.query(sql,
new BeanHandler<Product>(Product.class), pid);
return product;
}
// 修改
public int updateProduct(Product product) throws SQLException {
{
QueryRunner runner = new QueryRunner(
DataSourceUtils.getDataSource());
if (product.getPimage() == null) {
String sql = "update product set pname=?,market_price=?,shop_price=?,"
+ "is_hot=?,pdesc=?,pflag=?,cid=? where pid=?";
return runner.update(sql, product.getPname(),
product.getMarket_price(), product.getShop_price(),
product.getIs_hot(), product.getPdesc(),
product.getPflag(), product.getCid(), product.getPid());
} else {
String sql = "update product set pname=?,market_price=?,shop_price=?,"
+ "pimage=?,is_hot=?,pdesc=?,pflag=?,cid=? where pid=?";
return runner.update(sql, product.getPname(),
product.getMarket_price(), product.getShop_price(),
product.getPimage(), product.getIs_hot(),
product.getPdesc(), product.getPflag(),
product.getCid(), product.getPid());
}
}
}
- 关于增删改查方法中 public后的 返回值类型
- 关于radgird 中增删改查 的方法总结
- 关于增删改查的几个对象及方法
- JDBC封装增删改查,增加后返回主键等方法
- 增删改查返回值,调用DbHelper。
- 在wpf中调用的增删改查方法
- Android 中SQLite 增删改查的方法介绍
- Js中数组增删查改的方法
- 关于hbase增删改查的操作
- 关于项目的增删改查
- 关于thinkphp的增删改查
- 关于数据库的增删查改
- 关于json对象的增删改查
- 关于redis增删查改的步骤
- 数据库的增删改查方法
- SQLiteDataBase的增删改查方法参数
- ListView的增删改查等方法
- 安卓中数据库增删改查的方法
- 文章标题
- HashMap
- 二进制补码
- 私人数据
- LeetCode39
- 关于增删改查方法中 public后的 返回值类型
- Android解析JSON,你真的需要三方库?
- 数组 冒泡排序 选择排序 数组转置 可变参数
- Java并发编程:volatile关键字解析
- Python游戏编程入门第二章 笔记 第十页结束
- C语言正则表达式 regcomp&®exec
- TextAsset解析txt文档不识别中文问题
- java数据库基础(mysql)1
- Spring注解大全