WebWork2 + Spring + Hibernate Getting Started Fully Configuration Guide

xiaoxiao2021-03-06  40

Webwork is an excellent open source framework, especially its interceptor mechanism, I think it is the biggest highlight of the entire system, you can do a lot of articles on it, eclipse3.0.1 lomoz, database I use mysql4.0.12, Of course, I also used mysqlcc. The server I use Tomcat4.0.3 and Tomcat4.1, please download WebWork., Spring., Hibernate, put the JAR file in the lib directory of Web-INF. At the same time, please download http://unc.dl.sourceforge.net/source.zip, put the aopalliance.jar in the lib directory. There is also webwork2-spring.jar, as well as MySQL drivers to download and put it in Lib, shortness, then configuring log4j, if not properly configuring log, Tomcat will not form your project normally. Configuring log4j is very simple, establish a log4j.properties file under web-inf / class, as follows log4j.rootlogger = info, a1, r log4j.log4j.consolerappender log4j.consoleappender log4j.Appender.a1. Layout = org.apache.log4j.patternLayout log4j.Appender.a1.Layout.conversionPattern =% - D {yyyy-mm-dd hh: mm: s} [% C] - [% P]% m% n log4j.Appender .R = org.apache.log4j.RollingFileAppender log4j.appender.R.File = d: / Tomcat 4.1 / webapps / demo / logs / log4j.log log4j.appender.R.MaxFileSize = 100KB log4j.appender.R.MaxBackupIndex = 1 log4j.Appender.r.Layout = org.apache.log4j.patternLayout log4j.Appender.r.Layout.conversionPattern =% P% T% C -% M% n where the log4j.Appender.r.file This item follows Your Tomcat's installation location is modified, about the details of log4j, I recommend you to see Hilton's learning notes and related articles on IBM websites. Ok, start our webwork.

The first is to configure the web.xml file org.springframework.Web .context.ContextLoaderListener com.atlassian.xwork.ext.ResolverSetupServletContextListener webwork com.opensymphony.webwork.dispatcher.servletdispatcher Webwork *. Action Webwork /web-inf/webwork.tld We configure two listeners, there is a servlet, this servlet is responsible for Action's forwarding, about an action Detailed working principle, you can see the SWORK source code before you are configured, I want to talk about the function I want to implement, that is, insert some data into a table in MySQL first, first I use MiddleGen-Hibernate and Hibernate-Extensions. (I didn't use Eclipse's Hibernate plugin. I like to use these two tools to generate) generated the corresponding HBM.xml file and two Java classes, the field is "TableName, FieldName, Chineseamename", the table name is "SYSTABLE ", Where TableName, FieldName is dual primary key, so that the generated class should be two, a PK primary key class and the primary class itself, I added them into my project. Then I made an interface class package COM. CZ.Struct; / ** * @

author tijichen * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public interface SystableDAO {public abstract void insert (Systable data);} then the implementation class package com .cz.struct; import net.sf. *; import org.springframework.orm.hibernate.support.HibernateDaoSupport; / ** * @author tijichen * * TODO to change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public class SysTableDAOImp extends HibernateDaoSupport implements SystableDAO {. public void insert (systable data) {this.getHibernateTemplate () save (data);}} Why use interface class? Because Spring uses the dynamic agent of Java, about this part, you can see XIAXIN's Spring Guide In the Insert method, I directly call the Hibernate template method provided by Spring, it is convenient, then the Spring is configured, please in the web -LIB / Under the ApplicationContext.xml file, the content is as follows org.gjt.mm.mysql.driver jdbc: mysql: // localhost / mystructs chenzhi 1 COM / CZ / STRUCT / SYSTABLE.HBM.XML net.sf.hibernate .DIALECT.MYSQLDIALECT True

Propagation_required propagation_required, readonly propagation_required, readonly < / beans> In this profile, we set the DataSource / SessionFactory and Spring dynamic agents, as well as the XML mapping file path required for Hibernate and then configure xwork.xml s YSTABEDAOPROXY / index.jsp I have encountered a unclear joke when configuring an action, I am in editing XML, I have edited in Editplus, and I started me. Write

转载请注明原文地址:https://www.9cbs.com/read-64955.html

New Post(0)