快速业务通道

利用JBuilder 2005开发Spring实例 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-23
ice(Double d) { price = d; } public Double getPrice() { return price; } }

springapp/src/test/TestProductManagerDaoJdbc.java

package tests; import java.util.List; import java.util.ArrayList; import junit.framework.TestCase; import org.springframework.jdbc.datasource.DriverManagerDataSource; import db.ProductManagerDaoJdbc; import bus.Product; public class TestProductManagerDaoJdbc extends TestCase { private ProductManagerDaoJdbc pmdao; public void setUp() { pmdao = new ProductManagerDaoJdbc(); DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName("org.hsqldb.jdbcDriver"); ds.setUrl("jdbc:hsqldb:db/test"); ds.setUsername("sa"); ds.setPassword(""); pmdao.setDataSource(ds); } public void testGetProductList() { List l = pmdao.getProductList(); Product p1 = (Product) l.get(0); assertEquals("Lamp", p1.getDescription()); Product p2 = (Product) l.get(1); assertEquals("Table", p2.getDescription()); } public void testIncreasePrice() { List l1 = pmdao.getProductList(); Product p1 = (Product) l1.get(0); assertEquals(new Double("5.78"), p1.getPrice()); pmdao.increasePrice(p1, 10); List l2 = pmdao.getProductList(); Product p2 = (Product) l2.get(0); assertEquals(new Double("6.36"), p2.getPrice()); } }

利用JBuilder 2005开发Spring实例(8)

时间:2010-12-04

23. 修改Web应用使其使用数据库持久层

springapp/src/bus/ProductManager.java

package bus; import java.io.Serializable; import java.util.ListIterator; import java.util.List; import db.ProductManagerDao; public class ProductManager implements Serializable { private ProductManagerDao pmd; private List products; public void setProductManagerDao(ProductManagerDao pmd) { this.pmd = pmd; } /* public void setProducts(List p) { products = p; } */ public List getProducts() { products = pmd.getProductList(); return products; } public void increasePrice(int pct) { ListIterator li = products.listIterator(); while (li.hasNext()) { Product p = (Product) li.next(); /* double newPrice = p.getPrice().doubleValue() * (100 + pct)/100; p.setPrice(new Double(newPrice)); */ pmd.increasePrice(p, pct); } } }

springapp/war/WEB-INF/springapp-servlet.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- - Application context definition for "springapp" DispatcherServlet. --> <beans> <!-- Controller for the initial "Hello" page --> <bean id="springappController" class="web.SpringappController"> <property name="productManager"> <ref bean="prodMan"/> </property> </bean> <!-- Validator and Form Controller for the "Price Increase" page --> <bean id="priceIncreaseValidator" class="bus.PriceIncreaseValidator"/> <bean id="priceInc

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号