package springapp.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import springapp.domain.Product;
public class JdbcProductDao extends SimpleJdbcDaoSupport implements ProductDao {
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
public List<Product> getProductList() {
logger.info("Getting products!");
List<Product> products = getSimpleJdbcTemplate().query(
"select id, description, price from product",
new ProductMapper());
return products;
}
public void saveProduct(Product prod) {
logger.info("Saving product: " + prod.getDescription());
int count = getSimpleJdbcTemplate().update(
"update product set description = :description, price = :price where id = :id",
new MapSqlParameterSource().addValue("description", prod.getDescription())
.addValue("price", prod.getPrice())
.addValue("id", prod.getId()));
logger.info("Rows affected: " + count);
}
private static class ProductMapper implements ParameterizedRowMapper<Product> {
public Product mapRow(ResultSet rs, int rowNum) throws SQLException {
Product prod = new Product();
prod.setId(rs.getInt("id"));
prod.setDescription(rs.getString("description"));
prod.setPrice(new Double(rs.getDouble("price")));
return prod;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
spring+hibernate annotaion
共90个文件
class:17个
tld:16个
java:16个
需积分: 10 23 下载量 145 浏览量
2008-06-12
09:09:28
上传
评论
收藏 67KB RAR 举报
温馨提示
全基于annotaion的一个应用.通个注解的方式控制事务等 对于之前分要的太高了。给于补尝. 有兴趣的欢迎来群:41229007 共同学习
资源推荐
资源详情
资源评论
收起资源包目录
myspring.rar (90个子文件)
myspring
db
test.log 544B
test.lck 16B
load_data.sql 215B
test.script 451B
server.bat 82B
test.properties 428B
server.bat.bak 78B
create_products.sql 176B
build.xml 9KB
.settings
org.eclipse.jdt.ui.prefs 99B
org.eclipse.jdt.core.prefs 629B
src
springapp
repository
ProductDao.java 221B
JdbcProductDao.java 2KB
ProductHibernateDaoImpl.java 1KB
domain
Person.java 1KB
Event.java 765B
Product.java 859B
web
InsertProductController.java 1KB
InventoryController.java 1KB
PriceIncreaseFormController.java 2KB
HelloController.java 1KB
service
PriceIncreaseValidator.java 2KB
ProductManager.java 318B
InsertProduct.java 383B
InsertProductValidator.java 420B
SimpleProductManager.java 2KB
PriceIncrease.java 492B
main
conf
users.ldif 1KB
config
hibernate
entity
Person.hbm.xml 883B
Event.hbm.xml 716B
Product.hbm.xml 534B
jdbc.properties 250B
log4j.properties 792B
messages.properties 420B
messages_zh.properties 420B
util
.project 1KB
WebRoot
META-INF
MANIFEST.MF 39B
WEB-INF
scriptfree.tld 2KB
c-1_0.tld 11KB
applicationContext-security.xml 3KB
fmt-1_0.tld 12KB
fn.tld 7KB
web.xml 997B
fmt.tld 19KB
x.tld 12KB
x-1_0-rt.tld 7KB
fmt-1_0-rt.tld 11KB
x-1_0.tld 7KB
sql.tld 8KB
classes
users.ldif 1KB
config
hibernate
entity
Person.hbm.xml 883B
Event.hbm.xml 716B
Product.hbm.xml 534B
jdbc.properties 250B
log4j.properties 792B
springapp
repository
ProductHibernateDaoImpl.class 2KB
JdbcProductDao$ProductMapper.class 2KB
JdbcProductDao.class 3KB
ProductDao.class 291B
domain
Event.class 1KB
Product.class 1KB
Person.class 2KB
web
InventoryController.class 2KB
InsertProductController.class 2KB
PriceIncreaseFormController.class 2KB
HelloController.class 2KB
service
PriceIncreaseValidator.class 3KB
InsertProductValidator.class 810B
SimpleProductManager.class 2KB
ProductManager.class 345B
PriceIncrease.class 1KB
InsertProduct.class 815B
messages.properties 420B
main
util
messages_zh.properties 420B
sql-1_0.tld 6KB
jsp
priceincrease.jsp 868B
hello.jsp 601B
insertProductAction.jsp 1KB
include.jsp 159B
sql-1_0-rt.tld 5KB
springapp-servlet.xml 2KB
lib
c-1_0-rt.tld 11KB
tld
spring-form.tld 71KB
applicationContext.xml 5KB
permittedTaglibs.tld 1KB
c.tld 16KB
index.jsp 158B
build.properties 510B
.mymetadata 297B
.classpath 544B
.myeclipse
共 90 条
- 1
资源评论
wjalan
- 粉丝: 0
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功