Developed Spring instances using JBuilder 2005

xiaoxiao2021-03-06  14

1. Download the Spring package, the URL is as follows:

http://www.springframework.org/download.html

Decompressed directory contains DIST, LIB, etc.

2. Increase the Spring library in JBuilder 2005, select Menu Tools-Configure-Libraries, click the New button in the pop-up dialog box, enter the name of the Spring library: Spring, click the Add button to add all JAR files in the dist directory to Spring Library

3. New project files, select the menu file-new project, name to myProject to the project file

Set the properties of the project file, select the menu Project-Project Properties, select Tomcat as the server, join the Spring library to Path / Required Libraries. Because the log4j is used in the example, the library containing the log4j will be added to Path / Required Libraries, notice that there are two subdirectories LOG4J and JAKARTA-COMMONs in the lib directory, and their usage is different, as shown in the following code segment:

Log4j

import org.apache.log4j.Level; import org.apache.log4j.Logger; public class SpringappController implements Controller {/ ** Logger for this class and subclasses * / static Logger logger = Logger.getLogger (SpringappController.class); jakarta- commons import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SpringappController implements Controller {/ ** Logger for this class and subclasses * / protected final Log logger = LogFactory.getLog (getClass ())

4. Create a new web module, select the menu file-new, named SpringApp to the web module

5. New Hello.jsp files are as follows:

<% @ Page ContentType = "Text / HTML; Charset = BIG5"%> eXample :: Spring Application </ title> </ head> <body> <h1> Hello - Spring Application < / h1> <p> greetings. </ p> </ body> </ html></p> <p>6. New class files SpringAppController.java is as follows:</p> <p>package spring; import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http. HttpServletResponse; import java.io.IOException; // import org.apache.commons.logging.Log; // import org.apache.commons.logging.LogFactory; import org.apache.log4j.Level; import org.apache.log4j .Logger; public class SpringappController implements Controller {/ ** Logger for this class and subclasses * / // protected final Log logger = LogFactory.getLog (getClass ()); static Logger logger = Logger.getLogger (SpringappController.class); public ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException. {logger.info ( "SpringappController - returning hello view"); return new ( "hello.jsp") ModelAndView;}} 7 modify the web.xml file</p> <p><? XML Version = "1.0" encoding = "UTF-8"?> <! Doctype web-app public '- // sun microsystems, Inc.//dtd Web Application 2.3 // en' 'http: // java. Sun.com/dtd/web-app_2_3.dtd '> <web-app> <servlet> <servlet-name> springapp </ servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherServlet </ servlet -class> <load-on-startup> 1 </ loading-on-startup> </ servlet> <servlet-maping> <servlet-name> springapp </ servlet-name> <url-pattern> *. HTM </ URL-PATTERN> </ servlet-mapping> <welcome-file-list> <welcome-file> index.jsp </ welcome-file> </ welcome-file-list> </ web-app> 8. in Web- New springapp-servlet.xml file in the Inf directory is as follows</p> <p><? XML Version = "1.0" encoding = "UTF-8"?> <! Doctype beans public "- // Spring // DTD bean //" http://www.springframework.org/dtd/spring- Beans.dtd "> <! - Application Context definition for" springapp "dispatcherservlet. -> <beans> <bean id =" springappcontroller "class =" spring.springappcontroller "/> <bean id =" urlmapping "class = "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name = "mappings"> <props> <prop key = "/ hello.htm"> springappController </ prop> </ props> </ property> < / bean> </ beans> 9. New log4j.properties file in the web-inf directory is as follows:</p> <p>log4j.rootCategory = INFO, stdout, logfilelog4j.appender.stdout = org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout = org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern =% d% p [% c] - <% m>% nlog4j.appender.logfile org.apache.log4j.RollingFileAppenderlog4j.appender.logfile.File springapp.loglog4j.appender.logfile.MaxFileSize = 512KB # Keep three backup fileslog4j.appender.logfile.MaxBackupIndex = = = 3log4j.appender.logfile.layout = org.apache.log4j.PatternLayout # Pattern to output: date priority [category] - <message> line_separatorlog4j.appender.logfile.layout.ConversionPattern =% d% p [% c] - < % m>% N</p> <p>10. Set the web module SpringApp's property Content, add file log4j.properties, because the classes directory is automatically generated, this step is to add file log4j.properties to the classes directory. 11. Set the Run Configuration, select the menu Run-Configurations, create a new Run Configuration, Type selection server, launch URI set to: /springapp/hello.htm, name Hello 12. Run, you will look at the Messages window To the following information: News: Server Startup in 9253 MS2004-11-05 15: 05: 00, 585 info [Spring.SpringAppController] - <SpringAppController - Returning Hello View> 2004/1/5 03:05:00 Org.SpringFramework.Web .servlet.view.AbstractCachingViewResolver resolveViewName information: Cached view 'hello.jsp' increases in a row following myProject / Tomcat / springapp.log file shown: 2004-11-05 15: 11: 32,348 iNFO [spring.SpringappController] - <SpringAppController - Returning Hello View> This shows that you have successfully established basic Spring applications. JSTL support, set the properties of the project file, select the menu Project-Project Properties, join the JSTL library to Path / Required Libraries. 14. Improve the previous example, the improved documents are as follows: Add "Header" file include.jsp, this is a common part of some JSP files, which makes it easier for development and maintenance. All JSP files are placed in a web-INF / JSP directory, which is only Controller to access View. SpringApp / War / Web-INF / JSP / include.jsp <% @ page session = "false"%> <% @ taglib prefix = "c" uri = "http://java.sun.com/jstl/core" %> <% @ Taglib prefix = "fmt" URI = "http://java.sun.com/jstl/fmt"%> Using JSTL, <C: Redirect> Redirect the page to Controller, this is built in Index . JSP and the connection of the application architecture. Springapp / War / INDEX.JSP</p> <p><% @ Include file = "/ web-inf / jsp / include.jsp"%> <% - redirected Because We can't set the welcome page to a virtual url. -%> <c: redirect url = " /Hello.htm "/> utilizes JSTL's <C: OUT> tag, the current date and time extracted from MODEL, passed to the current date and time of the View. SpringApp / War / Web-INF / JSP / HELLO.JSP <% @ include file = "/ web-inf / jsp / include.jsp"%> <html> <head> <title> Hello :: Spring Application </ TITLE > </ Head> <body> <h1> Hello - Spring Application </ h1> <p> greetings, it is now <c: out value = "$ {now}" /> </ p> </ body> < / html> In SpringAppController.java, String contains the current date and time String as Model SpringApp / Src / SpringAppController.java</p> <p>import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SpringappController implements Controller {/ ** Logger for this class and subclasses * / protected final Log logger = LogFactory.getLog (getClass ()); public ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String now = (new java.util.Date ()) toString ();. logger.info ( "returning hello view With " now);" Web-INF / JSP / HELLO.JSP "," NOW ", NOW);}} 15. Browse improvements Http: // localhost: 8080 / springApp, first access Index.jsp, then redirect to Hello.htm, then handle the control to the controller, Controller transfer the date and time to View. Can only test it in the browser. Setting Run Configuration in JBuilder2005 cannot access http: // localhost: 8080 / springApp, but you can access http: // localhost: 8080 / SpringApp / index.jsp In the above example, Controller specifies the full path to the View, making Controller There is unnecessary dependence between the View. To remove this dependency, we can define this dependence in the properties file in the property file, and we can use the InternalResourceViewResolver to set the prefix and suffix using the InternalResourceViewResolver to set the prefix and suffix. Modify file springapp-servlet.xml Include ViewResolver settings, we also choose to use JSTLVIEW, which allows us to combine JSTL and Message Resource Bundles, so you can support internationalization. SpringApp / War / Web-Inf / SpringApp-Servlet.xml</p> <p><? XML Version = "1.0" encoding = "UTF-8"?> <! Doctype beans public "- // Spring // DTD bean //" http://www.springframework.org/dtd/spring- Beans.dtd "> <!- Application Context definition for" springapp "dispatcherservlet .--> <beans> <bean id =" springappcontroller "class =" springappcontroller "/> <bean id =" urlmapping "class =" org .springframework.web.servlet.handler.SimpleUrlHandlerMapping "> <property name =" mappings "> <props> <prop key =" / hello.htm "> springappController </ prop> </ props> </ property> </ bean > <bean id = "viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name = "viewClass"> <value> org.springframework.web.servlet.view.JstlView </ value> </ Property> <Property Name = "prefix"> <value> / web-inf / jsp / </ value> </ proty> <property name = "suffix"> <value> .jsp </ value> </ property > </ Bean> </ beans> Now we can remove the prefix and suffix of the View name in Controller.</p> <p>springapp / src / SpringappController.javaimport org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet .http.HttpServletResponse; import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SpringappController implements Controller {/ ** Logger for this class and subclasses * / protected final Log logger = LogFactory.getLog (getClass ()); public ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String now = (new java.util.Date ()) toString ();. logger. Info ("Returning Hello View with" Now); Return New ModelandView ("Hello", "NOW", NOW;}} This modified example should still run. 16. Add business logic to separate web logic and business logic, we build two different packages, web and bus springapp / src / bus / products, import java.io.serializable; public class product imports serializable {productive String description; private Double price; public void setDescription (String s) {description = s;} public String getDescription () {return description;} public void setPrice (Double d) {price = d;} public Double getPrice () {return Price;}} springapp / src / bus / productManager.java</p> <p>package bus; import java.io.Serializable; import java.util.List; public class ProductManager implements Serializable {private List products; public void setProducts (List p) {products = p;} public List getProducts () {return products;} } Modify SpringAppController.java SpringApp / src / Web / SpringAppController.java</p> <p>package web; import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.ModelAndView; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http. HttpServletResponse; import java.io.IOException; import java.util.Map; import java.util.HashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import bus.Product; import bus.ProductManager; public class SpringappController implements Controller {/ ** Logger for this class and subclasses * / protected final Log logger = LogFactory.getLog (getClass ()); private ProductManager prodMan; public ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response) Throws servletexception, ioException {string now = (new java.util.date ()). Tostring (); logger.info ("Returning Hello View with" now); map mymodel = new hashmap (); mymodel.put (" Now ", now); MyModel.Put (" products ", getProductManager (). getProducts (); return new ModelAndView ( "hello", "model", myModel);} public void setProductManager (ProductManager pm) {prodMan = pm;} public ProductManager getProductManager () {return prodMan;}} 17. View to display the modified business data, increased message Bundle's support SpringApp / WAR / Web-INF / JSP / HELLO.JSP</p> <p><% @ Include file = "/ web-inf / jsp / include.jsp"%> <html> <head> <title> <fmt: message key = "title" /> </ title> </ head> <body > <H1> <fmt: Message Key = "Heading" /> </ h1> <p> <fmt: Message Key = "Greeting" /> <c: out value = $ {model.now} "/> < / p> <h3> Products </ h3> <c: foreach items = "$ {model.products}" var = "prod"> <c: out value = "$ {prod.description}" /> <i> $ <c: out value = "$ {prod.price}" /> </ i> <br> <br> </ c: forEach> </ body> </ html> 18. we now add further test data Not intended to increase the code, load the business object from the database. We only add BEAN and Messagesource settings in SpringApp-Servlet.xml to provide some test data and support for Messages Resource Bundle. SpringApp / War / Web-Inf / SpringApp-Servlet.xml</p> <p><? XML Version = "1.0" encoding = "UTF-8"?> <! Doctype beans public "- // Spring // DTD bean //" http://www.springframework.org/dtd/spring- beans.dtd "> <! --- Application context definition for" springapp "DispatcherServlet .--> <beans> <bean id =" springappController "class =" web.SpringappController "> <property name =" productManager "> <ref Bean = "prodman" /> </ proty> </ bean> <bean id = "prodman" class = "bus.productmanager"> <property name = "products"> <list> <ref bean = "product1" /> <Ref bean = "product2" /> <ref bean = "Product3" /> </ list> </ proty> </ bean> <bean id = "product1" class = "bus.product"> <property name = " Description "> <value> Lamp </ value> </ profy> <property name =" price "> <value> 5.75 </ value> </ property> </ bean> <bean id =" Product2 "class =" BUS .Product "> <property name =" description "> <value> Table </ value> </ proty> <property name =" price "> <value> 75.25 </ value> </ property> </ bean> <bean ID = "Product3" Class = "bus.product"> <</p> <p>Property name = "description"> <value> chair </ value> </ property> <property name = "price"> <value> 22.79 </ value> </ print = "messagesource" class = "org.springframework.context.support.ResourceBundleMessageSource"> <property name = "basename"> <value> messages </ value> </ property> </ bean> <bean id = "urlMapping" class = "org. springframework.web.servlet.handler.SimpleUrlHandlerMapping "> <property name =" mappings "> <props> <prop key =" / hello.htm "> springappController </ prop> </ props> </ property> </ bean> <bean id = "viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name = "viewClass"> <value> org.springframework.web.servlet.view.JstlView </ value> < / Property> <property name = "prefix"> <value> / web-inf / jsp / </ value> </ property> <property name = "suffix"> <value> .jsp </ value> </ property> </ Bean> </ beans> 19. Increasing Message Bundle SpringApp / War / Web-INF / CLASSES / Messages.properties</p> <p>Title = SpringAppHeading = Greetings, IT IS NOW 20. Browse improvements HTTP: // localhost: 8080 / springApp Implement database persistence 21. Set HSQL database, add HSQL libraries in JBuilder2005, select Menu Tools -Configure-libraries, click the New button in the pop-up dialog box, enter the name of the HSQL library: HSQL, click the Add button to add filesqldb.jar in the lib / hsqldb directory to the HSQL library. Select Menu Enterprise-Enterprise Setup, select Database Drivers in the pop-up dialog box, press the Add button to increase the HSQL library. Select Menu Tools-Database Pilot, then select Menu Files-New Enter DRIVER: Org.hsqldb.jdbcdriver, URL: JDBC: HSQLDB: DB / TEST, Double-click HSQLDB: DB / Test, Enter username: SA, do not have to enter Passsword. Input and execute the following SQL statements CREATE TABLE products (id INTEGER NOT NULL PRIMARY KEY, description varchar (255), price decimal (15,2)); CREATE INDEX products_description ON products (description); INSERT INTO products (id, description, VALUES (1, 'Lamp', 5.78); Insert Into Products (ID, Description, Price) VALUES (2, 'Table', 75.29); Insert Into Products (ID, Description, Price) VALUES (3, 'Chair ', 22.81); this will create a directory DB in the jbuilder_home / bin directory, store Database Test data 22. Create JDBC DAO (Data Access Object) to implement SpringApp / src / db / productManagerDao.java</p> <p>package db; import bus.Product; import java.util.List; public interface ProductManagerDao {public List getProductList (); public void increasePrice (Product prod, int pct);} springapp / src / db / ProductManagerDaoJdbc.java</p> <p>package db; import bus.Product; import java.util.List; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import javax.sql.DataSource; import org.apache.commons. logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.object.MappingSqlQuery; import org.springframework.jdbc.object.SqlUpdate; import org.springframework.jdbc.core.SqlParameter; public class ProductManagerDaoJdbc implements ProductManagerDao {/ ** Logger for this class and subclasses * / protected final Log logger = LogFactory.getLog (getClass ()); private DataSource ds; public List getProductList () {logger.info ( "Getting products!"); ProductQuery pq = new ProductQuery (ds); return pq.execute ();} public void increasePrice (Product prod, int pct) {logger.info ( "Increasing price by" pct "%"); SqlUpdate su = new SqlUpdate (DS, "Update Products Set Price = Price * (100 ?) / 100 WHERE ID =?"); Su.DeclareParameter ("Increase", Types.integer); Su.Declare Parameter ("ID", Types.integer); Su.compile (); Object [] OA = New Object [2]; OA [0] = New Integer (PCT); OA [1] = New Integer ()); int count = su.update (OA); Logger.info ("Rows Affected:" count);} public void setDataSource (DataSource DS) {this.ds = DS;} Class ProductQuery Extends MappingSqlQuery {ProductQuery (DataSource ds) {super (ds, "SELECT id, description, price from products"); compile ();} protected Object mapRow (ResultSet rs, int rowNum) throws SQLException {Product prod = new Product (); PROD.SETID (Rs.Getint ("ID")); prod.setdescription (rs.getstring ("</p> <p>Description ")); prod.setprice (NEW DOUBLE (" price "))))); returnified,}}} springapp / src / bus / product.javaPackage bus; import java.io.serializable; Public Class Product implements Serializable {private int id; private String description; private Double price; public void setId (int i) {id = i;} public int getId () {return id;} public void setDescription (String s) {description = s; } public String getDescription () {return description;} public void setPrice (Double d) {price = d;} public Double getPrice () {return price;}} springapp / src / test / TestProductManagerDaoJdbc.java</p> <p>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 testProductList () {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 TestinCreasepricePrice () {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 P 2 = (Product) L2.GET (0); Assertequals (New Double ("6.36"), P2.GetPrice ());}} 23. Modify the web application to use database persistence SpringApp / src / bus / productManager. Java</p> <p>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 = () li.next (); / * double newprice = p.getPrice (). DoubleValue () * (100 PCT ) /100q; new double (new price)); * / pmd.increaseprice (p, pct);}}} springapp / war / web-inf / springapp-servlet.xml</p> <p><? XML Version = "1.0" encoding = "UTF-8"?> <! Doctype beans public "- // Spring // DTD bean //" 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 "/> </ proty> </ bean> <! - validator and form controller for the" price increas "page -> <bean id = "priceIncreaseValidator" class = "bus.PriceIncreaseValidator" /> <bean id = "priceIncreaseForm" class = "web.PriceIncreaseFormController"> <property name = "sessionForm"> <value> true </ value> </ property> < Property name = "commandname"> <value> priceIncrease </ value> </ proty> <property name = "commandclass"> <value> bus.priceincrease </ value> </ print> <property name = "validator"> < Ref bean = "priceIncreasevalidator" /> </ print "> <value =" formview "> <value> priceincrease </ value> </ property> <property name =" surpassView "> <value> Hello.htm </ valu e> <</p> <p>/ Property> <property name = "productManager"> <ref bean = "prodman" /> </ proty> </ bean> <bean id = "datasource" class = "org.springframework.jdbc.datasource.drivermanagerDataSource"> < Property name = "driverclassname"> <value> org.hsqldb.jdbcdriver </ value> </ property> <property name = "url"> <value> jdbc: hsqldb: / home / trisberg / workspace / SpringApp / db / test </ Value> </ proty> <property name = "username> <value> sa </ value> </ property> <property name =" password "> <value> </ value> </ property> </ bean > <Bean id = "prodmandao" class = "db.productManagerdaojdbc"> <property name = "datasource"> <ref bean = "datasource" /> </ property> </ bean> <bean id = "prodman" class = "Bus.ProductManager> <property name =" productManagerdao "> <ref bean =" prodmandao "/> <property name =" products "> <list> <ref bean =" product1 "/ > <Ref bean = "product2" /> <ref bean = "product3" /> </ list> </ print "/> </ bean> <! - <bean id =" product1 "class =" bus. Product "> <</p> <p>Property name = "description"> <value> Lamp </ value> </ property> <property name = "price"> <value> 5.75 </ value> </ proty> </ bean> <bean id = "product2" Class = "bus.product"> <property name = "description"> <value> Table </ value> </ property> <property name = "price"> <value> 75.25 </ value> </ property> </ Bean> <bean id = "product3" class = "bus.product"> <property name = "description"> <value> chair </ value> </ property> <property name = "price"> <value> 22.79 < / value> </ proty> </ bean> -> <bean id = "message" class = "org.springframework.context.support.resourcebundleMessageSource"> <property name = "basename> <value> Messages </ value > </ Print = "Urlmapping" class = "org.springframework.web.servlet.handler.simpleurlhandlermapping"> <property name = "mappings> <props> <prop key =" / Hello .htm> SpringAppController </ prop> <prop key = "/ priceincrease.htm"> PriceIncreaseform </ prop> </ props> </ property> </ bean> <bean id = "</p> <p>viewResolver "class =" org.springframework.web.servlet.view.InternalResourceViewResolver "> <property name =" viewClass "> <value> org.springframework.web.servlet.view.JstlView </ value> </ property> <property Name = "prefix"> <value> / web-inf / jsp / </ value> </ proty> <property name = "suffix"> <value> .jsp </ value> </ property> </ bean> < / beans> springapp / src / tests / MockProductManagerDaoImpl.javapackage tests; import bus.Product; import java.util.List; import db.ProductManagerDao; import bus.Product; public class MockProductManagerDaoImpl implements ProductManagerDao {private List products; public void setProducts ( List p) {products = p;} public List getProductList () {return products;}. public void increasePrice (Product prod, int pct) {double newPrice = prod.getPrice () doubleValue () * (100 pct) / 100 PROD.SETPRICE (New Double (NewPrice));}} SpringApp / src / Tests / Web-INF / SPRINGAPPPPP-Servlet.xml</p> <p><? XML Version = "1.0" encoding = "UTF-8"?> <! Doctype beans public "- // Spring // DTD bean //" http://www.springframework.org/dtd/spring- beans.dtd "> <! --- Application context definition for" springapp "DispatcherServlet .--> <beans> <bean id =" springappController "class =" web.SpringappController "> <property name =" productManager "> <ref Bean = "prodman" /> </ profment> </ bean> <bean id = "prodmandao" class = "tests.mockproductmanagerdaoImpl> <property name =" products> <list> <ref bean = "product1" /> <Ref bean = "product2" /> <ref bean = "product3" /> </ list> </ proty> </ bean> <bean id = "prodman" class = "bus.productmanager"> <property name = " ProductManagerDao> <ref bean = "prodmandao" /> <property name = "products> <list> <ref bean =" product1 "/> <ref bean =" product2 "/> < Ref bean = "product3" /> </ list> </ proty> -> </ bean> <bean id = "product1" class = "bus.product"> <property name = "description"> <value> Lamp </ Value> </ proty> <property name = "price"> <</p> <p>Value> 5.75 </ value> </ property> </ bean> <bean id = "product2" class = "bus.product"> <property name = "description"> <value> Table </ value> </ property> <Property Name = "Price"> <value> 75.25 </ value> </ property> </ bean> <bean id = "product3" class = "bus.product"> <property name = "description"> <value> Chair </ value> </ property> <property name = "price"> <value> 22.79 </ value> </ property> </ bean> </ beans> SpringApp / src / tests / testproductmanager .java</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-49173.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="49173" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.039</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '6Ui_2FB6aCEWRNiCawdQtmkg_2Fc1_2BJO5lwJfGqi2ngIkx3gjNivo3Kv49XM_2BH2ax39LyyUkejl74FFBD_2BHN'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>