"Java EE Spring" 12, integrated SSH Framework (end version)

Source: Internet
Author: User

"Java EE Spring" 12, integrated SSH Framework (end version)

Finally, we send the whole project, the code, people do not want to download the project, you can see all the code here (because the project needs a download points, really not much =, I think I have been so long, collect points should not be excessive ... Hey

Here, I try to make it, lest the copy and paste, the strange annoying

First, the overall project



Second, start all the code
Person.java



Person.hbm.xml



Personservice.java

Package Cn.cutter_point.service;import Java.util.list;import Cn.cutter_point.bean.person;public interface Personservice {//This business bean implements several methods, saves, updates, deletes, gets, gets all public abstract void Save (person Persnon);p ublic abstract void Update ( Person person);p ublic abstract void Delete (integer personid);p the ublic abstract person Getperson (integer personid);p ublic Abstract list<person> getpersons ();}

Personservicebean

/** * Function: Implement SSH integration hibernate4+spring4+struts2, this is an entity bean * Time: March 28, 2015 21:13:10 * author:cutter_point * File: Person.java */package Cn.cutter_point.service.impl;import Java.util.list;import Javax.annotation.resource;import Org.hibernate.sessionfactory;import Org.springframework.transaction.annotation.propagation;import Org.springframework.transaction.annotation.transactional;import Cn.cutter_point.bean.person;import Cn.cutter_ Point.service.PersonService, @Transactionalpublic class Personservicebean implements Personservice {@Resource// This is the dependency injection private sessionfactory sessionfactory;//This business bean implements several methods, save, UPDATE, delete, fetch, get all @overridepublic void Save (person person) {sessionfactory.getcurrentsession (). persist (person);} @Overridepublic void update (person person) {sessionfactory.getcurrentsession (). Merge (person);} @Overridepublic void Delete (Integer PersonID) {sessionfactory.getcurrentsession (). Delete ( Sessionfactory.getcurrentsession (). Get (Person.class, PersonID));} @Override @transactional (Propagation=propagatiOn. not_supported,readonly=true) Public person Getperson (Integer PersonID) {return (person) Sessionfactory.getcurrentsession (). Get (Person.class, PersonID);} @SuppressWarnings ("unchecked")//Cancel Warning @transactional (propagation=propagation.not_supported,readonly=true) @ Overridepublic list<person> getpersons () {return sessionfactory.getcurrentsession (). CreateQuery ("from" ). List ();}}

Personaction.java

/** * Features: Integrated SSH framework * author:cutter_point * Time: March 29, 2015 17:30:07 */package Cn.cutter_point.web.action;import Javax.annotation.resource;import Javax.servlet.servletcontext;import javax.servlet.http.HttpServletRequest; Import Org.apache.struts2.servletactioncontext;import Org.springframework.web.context.WebApplicationContext; Import Org.springframework.web.context.support.webapplicationcontextutils;import Cn.cutter_point.bean.Person; Import Cn.cutter_point.service.personservice;import Com.opensymphony.xwork2.actionsupport;public class Personaction extends Actionsupport {@Resource private personservice personservice;//first injected by name, if not found, inject private by type String name;//name public string GetName () {return name;} public void SetName (String name) {this.name = name;} Public String Add () throws Exception{personservice.save (name); return "Add";} Public String list () throws Exception {/*//Gets the instance, method 1ServletContext sc = servletactioncontext.getrequest (). GetSession (). Getservletcontext (); WebapplicationcontextWAC = (webapplicationcontext) sc.getattribute (Webapplicationcontext.root_web_application_context_attribute);// Method 2WebApplicationContext Webapplicationcontext = Webapplicationcontextutils.getrequiredwebapplicationcontext ( Servletactioncontext.getservletcontext ()); if (WAC = = Webapplicationcontext) {System.out.println ("OK!!!");} Personservice Personservice = (personservice) wac.getbean ("Personservicebean"); */httpservletrequest request = Servletactioncontext.getrequest (); Request.setattribute ("Persons", Personservice.getpersons ()); return "List";}}

Personservicetest.java

Package Junit.test;import static Org.junit.assert.*;import Java.util.list;import Org.junit.beforeclass;import Org.junit.test;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;import Cn.cutter_point.bean.person;import Cn.cutter_point.service.personservice;public class Personservicetest {private static Personservice personservice;@ Beforeclasspublic static void Setupbeforeclass () throws Exception {try {applicationcontext applicationcontext = new Class Pathxmlapplicationcontext ("Applicationcontext.xml");p Ersonservice = (personservice) Applicationcontext.getbean (" Personservicebean ");} catch (Exception e) {e.printstacktrace ();}} @Testpublic void Testsave () {//fail ("not yet implemented");p Ersonservice.save (The new person ("cutter_point"));} @Testpublic void Testupdate () {//fail ("not yet implemented"); Person person = Personservice.getperson (2);//....person.setname ("Xiao Li");p ersonservice.update (person); @Testpublic void TestdeleTe () {//fail ("not yet implemented");p Ersonservice.delete (9);} @Testpublic void Testgetperson () {Person person = Personservice.getperson (2); System.out.println (Person.getname ()); SYSTEM.OUT.PRINTLN ("Close data area =========="), try {thread.sleep (1000*30);//15 second} catch (Interruptedexception e) { E.printstacktrace ();} SYSTEM.OUT.PRINTLN ("Get data for the second time");p Erson = Personservice.getperson (2); System.out.println (Person.getname () + "++++++++++");} @Testpublic void Testgetpersons () {list<person> persons = Personservice.getpersons (); for (person person:persons) {System.out.println (Person.getname ());}}}

Applicationcontext.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:aop= "Http://www.springframework.org/schema/aop" xmlns: Mvc= "Http://www.springframework.org/schema/mvc" xmlns:jdbc= "Http://www.springframework.org/schema/jdbc" xmlns: Cache= "Http://www.springframework.org/schema/cache" xsi:schemalocation= "http://www.springframework.org/schema/ JDBC HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/JDBC/SPRING-JDBC-4.1.XSDHTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP/SPRING-AOP-4.1.XSDHTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC/HTTP Www.springframework.org/schema/mvc/spring-mvc-4.1.xsdhttp://www.springframework.org/schema/beans/HTTP Www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/cache/HTTP Www.springframework.org/scheMa/cache/spring-cache-4.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-4.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.1.xsd "><context:annotation-config/><!--<bean id=" DataSource [class=] Org.springframework.jdbc.datasource.DriverManagerDataSource "><property name=" Driverclassname "value=" Com.mysql.jdbc.Driver "/><property name=" url "value=" jdbc:mysql://localhost:3306/cutter_point?useunicode= True&characterencoding=utf-8 "/><property name=" username "value=" root "/><property name=" password " Value= "xiaofeng2015"/></bean>--><!--recommended configuration--><bean id= "myDataSource" class= " Org.apache.commons.dbcp2.BasicDataSource "destroy-method=" close "><!--results in a setdriverclassname (String) Call--><property name= "Driverclassname" value= "Com.mysql.jdbc.Driver"/><property name= "url" value= " Jdbc:mysql://localHost:3306/cutter_point "/><property name=" username "value=" root "/><property name=" password "value="  xiaofeng2015 "/><!--The initial value of the connection pool startup--><property name=" InitialSize "value=" 1 "/><!--the maximum value of the connection pool There seems to be no--><!--<property name= "maxactive" value= "Dbcp2"/>--><!--  Maximum idle value. After a peak time, the connection pool can slowly release a portion of the connection that has not been used, and has been reduced to maxidle until--><property name= "Maxidle" value= "2"/><!-- Minimum idle value. When the number of idle connections is less than the threshold, the connection pool will be pre-applied to some connections, so as not to apply--><property name= "Minidle" value= "1"/></bean><!-- <bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" ><property Name= "DataSource" ref= "DataSource"/> Scan entity class <property name= "Packagestoscan" value= "Com.tzl"/>hibernate configuration <property name= "Hibernateproperties" ><value>hibernate.dialect=  Org.hibernate.dialect.mysqldialecthibernate.show_sql=truehibernate.format_sql=truehibernate.hbm2ddl.auto=none Other values Create, Create-drop, update, Validatehibernate.current_sessiOn_context_class=threadhibernate.temp.use_jdbc_metadata_defaults=false</value></property></bean >--><!--Hibernate level Two cache configuration--><bean id= "Sessionfactory" class= " Org.springframework.orm.hibernate4.LocalSessionFactoryBean "><!--configuration elided for brevity-->< Property Name= "DataSource" ref= "myDataSource"/><property name= "mappingresources" ><list><!--mapping file --><value>cn/cutter_point/bean/person.hbm.xml</value></list></property><property Name= "Hibernateproperties" ><!--the property configuration used to configure Hibernate--><value>hibernate.dialect= Org.hibernate.dialect.mysqldialecthibernate.hbm2ddl.auto=update <!--Other values Create, Create-drop, update, validate None-->hibernate.show_sql=truehibernate.format_sql=true<!--turn on level two cache function-->hibernate.cache.use_second_ Level_cache = Truehibernate.cache.use_query_cache = Falsehibernate.cache.region.factory_class = Org.hibernate.cache.ehcache.EhCacheRegionFactory <!--hibernate3 Level Two cache configuration-<!--<property name= "Hibernate.cache.provider_class" >org.hibernate.cache.eh Cacheprovider</property>--</value></property></bean><!--configuration transaction manager for Hibernate-- ><bean id= "Txmanager" class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" >< Property Name= "Sessionfactory" ref= "sessionfactory"/></bean><!--use annotations to manage transactions--><tx: Annotation-driven transaction-manager= "Txmanager"/><bean id= "Personservicebean" class= "Cn.cutter_ Point.service.impl.PersonServiceBean "/><bean id=" personaction "class=" Cn.cutter_ Point.web.action.PersonAction "autowire=" ByName "/></beans>

Ehcache.xml


<!--~ Hibernate, relational persistence for idiomatic Java ~ ~ Copyright (c), Red Hat middleware LLC or third- Party contributors as ~ indicated by the @author tags or express copyright attribution ~ Statements applied by the Autho Rs.  All third-party contributions is ~ distributed under license by Red Hat middleware LLC. ~ ~ This copyrighted material are made available to anyone wishing to use, modify, ~ copy, or redistribute it subject to  The terms and conditions of the GNU ~ Lesser general public License, as published by the Free software Foundation. ~ ~ This program was distributed in the hope that it'll be useful, ~ but without any WARRANTY;  Without even the implied warranty of merchantability ~ or FITNESS for A particular PURPOSE.  See the GNU Lesser general public License ~ to more details. ~ You should has received a copy of the GNU Lesser general public License ~ along with this distribution;  If not, write to: ~ Free Software Foundation, Inc. ~Wuyi Franklin Street, Fifth Floor ~ Boston, MA 02110-1301 USA--><ehcache> <!--sets the path to the dire         Ctory where cache. data files are created.         If the path is a Java System, the It is replaced by its value in the running VM. The following properties are Translated:user.home-user ' s home directory User.dir-user's current Worki ng Directory Java.io.tmpdir-default temp file path--<!--cache files to hard drive where--<diskstore PA Th= "G:\Workspaces\MyEclipse Professional 2014\ssh\cachefile"/> <!--Default Cache configuration.        These would applied to caches programmatically created through the CacheManager.  The following attributes is required for defaultcache:maxinmemory-sets the maximum number of objects that 'll is created in memory eternal-sets whether elements is eternal.                      If Eternal, timeouts is ignored and the element      is never expired. Timetoidleseconds-sets the time to idle for an element before it expires. Was only used if the element was not eternal. Idle time is now-last accessed time timetoliveseconds-sets the time-to-live for a element before it expires. Was only used if the element was not eternal.                            TTL is now-creation time overflowtodisk-sets whether elements can overflow to disk time the In-memory cache        has reached the maxinmemory limit. -<!--defaultcache node is the default cache policy maxelementsinmemory the maximum allowable number of objects in memory eternal sets whether objects in the cache will never expire ov Erflowtodisk the overflow object to the hard disk timetoidleseconds the specified cache object is idle for an extended period of time, the expired object is erased timetoliveseconds the total lifetime of the specified cache object diskpers Istent the end of the JVM is whether to persist the object diskexpirythreadintervalseconds specifies the polling time of the listener thread dedicated to purging expired objects--<defaultcache Maxelem Entsinmemory= "10000" eternal= "false" timetoidleseconds= "120"Timetoliveseconds=" overflowtodisk= "true"/> <!--Special Configuration items--<cache name = "Cn.cutter_point.bean.Person" maxelementsinmemory= "eternal=" "false" timetoidleseconds= "Timetoliveseconds" = "" overflowtodisk= "true"/> </ehcache>

Struts.xml



addperson.jsp



personlist.jsp



Xml




Third, the use of the jar package




All right, that's all, and then upload the project.

Connection Address: http://download.csdn.net/detail/cutter_point/8548263






"Java EE Spring" 12, integrated SSH Framework (end version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.