Spring Framework Learning Notes (iv)

Source: Internet
Author: User
Tags aop

Pick up Spring Framework Learning Note (iii) declarative Transaction management (XML configuration)

1 configuration file mode using AOP idea configuration

The first step is to configure the transaction manager

Second step to configure transaction enhancements

Step three Configure Facets

Declarative transaction management (annotations)

The first step is to configure the transaction manager

Second step to configure transaction annotations

The third step is to add annotations to the class where you want to use the transaction

SSH three-frame integration:(1) struts2 (2) hibernate5.x (3) spring4.x review SSH framework Knowledge points: Hibernate framework

1 Hibernate core configuration file

(0) ORM Ideas

-Object Relational Mapping

(1) Database information

(2) Hibernate information

(3) Mapping configuration

(4) Hibernate core configuration file

-If you simply use the Hibernate framework, the core profile name Hibernate.cfg.xml and the location src under fixed

-Hibernate and Spring integration, Hibernate core profile name and location does not have a fixed requirement

2 Hibernate mapping configuration file

(1) Entity class and database table mapping relationship-using ORM Ideas

3 Steps for Hibernate operation

(1) The Hibernate framework is encapsulated in the spring framework, using the Hibernatetemplate

Struts2 Frame

1 Action Action

(1) Action to create three different ways

-Inheriting class Actionsupport

(2) Configuring the Action access Path

-Create Struts.xml config file, this file name and location fixed src below

(3) Configuring multiple methods to access the action

-Configure with wildcard characters

(4) Submit data in action get form

-Get Request Object

* * Using the Servletactioncontext class to get

-Attribute Encapsulation

-Model driven (emphasis)

-Expression Encapsulation

(5) In Action Action Field object

-Use Servletactioncontext to get domain objects

(6) Configure the STRUTS2 filter

2 Value Stacks

(1) Putting data into the value stack

-Set method

-Push method

-Define variables, generate Get methods

(2) Fetching data from the value stack

-Use struts2 tag +OGNL in JSP to get

-<s:property>

-<s:iterator>

3 Interceptors

(1) AOP and responsibility chain model

(2) Custom interceptors

-Inherit Methodfilterinterceptor

-Rewrite the method inside the class

-Configure interceptors and action associations

Spring Framework

1 Spring Core configuration file

(1) No fixed requirement for name and location

(2) Introducing schema constraints in the spring core configuration file

2 Creating objects

(1) How to configure XML: <bean id= "" class= "" scope= ""/>

(2) Annotation method: four annotations

3 Injection Properties (object type properties)

(1) How to configure XML:

(2) Annotation method: two annotations

-Autowired

-Resource

3 implementation using ServletContext objects and listeners

(1) When the server starts, load the spring configuration file, create the object

(2) Configuring the Spring Listener

(3) Specify the spring configuration file location

4 JdbcTemplate

5 Spring Transaction Configuration

(1) XML mode

(2) How to annotate

SSH Framework Integration idea

13 Large frame application in Java EE three layer structure

2 STRUTS2 framework and Spring integration

(1) Struts2 action in spring configuration

3 Spring Framework and Hibernate framework Integration

(1) Hibernate sessionfactory is given to spring configuration

(2) give the Hibernate database configuration to the spring configuration

Integrate STRUTS2 and spring frameworks

1 give the struts2 action to spring management

2 Implementation Process

The first step is to import the Struts2 jar package

(1) Importing JAR packages for consolidation

Step two create the action

The third step is to create the STRUTS2 core configuration file and configure the action

(1) position under SRC, name is Struts.xml

Fourth Step configuration struts2 Filter

Fifth step to import the Spring jar package

Sixth step to create a spring configuration file

(1) Introducing constraints

(2) Configuring the Spring Listener

(3) Specify the spring configuration file location

The seventh step gives the action to spring configuration (* * *)

(1) Configuring the Action object in spring, and also configuring the Action object in Struts.xml

(2) Settlement:

You only need to configure the action object in spring, not in the Struts.xml

Spring Framework integrates Hibernate framework

1 Configure database information in Hibernate core configuration file, configure database information in spring

2 Create the Sessionfactory in Hibernate and give it to spring management

Specific implementation

The first step is to import the Hibernate jar package

(1) Jar conflict problem when importing jar packages for struts2 and hibernate

Inside the struts2, there's a jar bag.

There's a jar bag in hibernate.

Remove the lower version of the jar package

(2) Importing the Spring Consolidated Persistence Layer Framework requires importing JAR packages

Setting up Hibernate environment in the second step

1 Creating an Entity class

2 Configuring Entity class mapping relationships

3 Creating a core configuration file

The third step is to configure the Hibernate core profile database and configure it in spring.

(1) Remove the database configuration from the Hibernate core file in the spring configuration

The fourth step is to give Hibernate's sessionfactory to spring configuration

(1) When the server starts, the spring configuration file is loaded and the objects in the configuration file are created

(2) Create the Sessionfactory object in spring configuration

(3) because the creation of the Sessionfactory code is not new, but the implementation of multiple lines of code

(4) Spring inside for the above situation, encapsulation class, configuration class object can create Sessionfactory

The fifth step is to use hibernatetemplate inside DAO

(1) object that gets hibernatetemplate in DAO

(2) Call Hibernate template inside the Save method to add

No transaction configured, exception occurred during operation

Sixth Step Configuration transaction

Hibernatetemplate Introduction

1 Hibernatetemplate The Hibernate framework is encapsulated,

Directly invoke Hibernatetemplate inside the method to implement the function

2 Common methods of Hibernatetemplate

    • Serializable Save (Object entity): Add operation
    • void update (Object entity): Modify operation
    • void Delete (Object entity): delete operation
    • <T> T Get (class<t> entityclass, Serializable ID): Query by ID
    • <T> T Load (class<t> entityclass, Serializable ID): Query by ID

    • List Find (String queryString, Object ... values): Methods for querying operations

(1) The first parameter is a HQL statement

(2) Statement parameter value

Review the SSH Framework integration process again:

First Step import jar package

Second step to build STRUTS2 environment

(1) Create action, create struts.xml configuration file, configure action

(2) Configure the STRUTS2 filter

Third step to build hibernate environment

(1) Create an entity class

(2) Configuring Entity classes and database table mapping relationships

(3) Create Hibernate core profile

-Introduction of mapping profiles

Fourth step to build the spring environment

(1) Creating a spring core configuration file

(2) Let the spring configuration file load when the server starts

-Configure Listeners

-Specify the spring configuration file location

Fifth step struts2 and spring integration

(1) Configure action in spring (action multi-instance)

(2) write the bean ID value in the action tag class attribute in Struts.xml

Sixth step spring and hibernate integration

(1) Set the Hibernate core configuration file database configuration in spring

(2) Configure Hibernate's sessionfactory in spring

The seventh step is to use hibernatetemplate inside DAO

(1) Inject Hibernatetemplate object in DAO

(2) Inject sessionfactory into the Hibernatetemplate object

Eighth Step configuration Transaction

Other ways to integrate

1 Spring integration Hibernate, you can not write hibernate core configuration file

(1) Put the basic information configuration and mapping into the spring configuration in the Hibernate core configuration file.

Spring Sub-module development

1 Configure multiple content in spring, resulting in configuration confusion, not using maintenance

2 in the spring core configuration file, a subset of the configurations are placed in a separate configuration file, and a separate profile is introduced in the spring core configuration file

The spring framework is here for the time being.

Spring Framework Learning Notes (iv)

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.