Spring Employee Management System SSH 1

Source: Internet
Author: User

"Configure Spring and test"

??

Introduce the Spring package and write the applicationcontext.xml file, which is placed in the src directory

??

Create a domain package and write an employee class Employee.java

??

In Employee.java

??

public class Employee

{

Private Integer ID;

private String name;

Private String Email;

Private String pwd;

private Integer grade;

Private Java.util.Date hiredate;

Private Float salary;

??

Public Employee () {}

??

Public Employee (string name, string email, string pwd, Integer grade,

Date HireDate, Float salary)

{

THIS.name = name;

This.email = email;

This.pwd = pwd;

This.grade = grade;

This.hiredate = hiredate;

This.salary = salary;

}

??

// setfor each attribute field,get method

}

??

Configuring Beans in the applicationcontext file

??

<bean id= "employee" class= "Com.hsp.domain.Employee ( class path, including package path, not behind java)" >

<property name= "name" value= "Tong"/>

</bean>

??

New test class Test.java, test in the main function of Test.java

??

ApplicationContext ac=new classpathxmlapplicationcontext ("Applicationcontext.xml");

Employee Employee=ac.getbean ("employee");

??

"Configure Hibernate"

??

The hibernate.cfg.xml file Object mapping file and Sessionfactory are configured in the Spring file

??

Introducing Hibernate Packages

??

Configure the data source because Spring advocates development of the data source

??

<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >

<!-- This section is the same as hibernate Configuration -

<property name= "Driverclassname" value= "Oracle.jdbc.driver.OracleDriver"/>

<property name= "url" value= "JDBC:ORACLE:THIN:@127.0.0.1:1521:ORCLHSP"/>

<property name= "username" value= "Scott"/>

<property name= "password" value= "Tiger"/>

<!-- Initial value when connection pooling starts- -

<property name= "InitialSize" value= "3"/>

<!-- The maximum value of the connection pool--

<property name= "maxactive" value= "/>"

<!-- Maximum idle value . After a peak time, the connection pool can slowly release a portion of a 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 free connections is less than the threshold, the connection pool will pre-apply for some connections to avoid the flood Peak when it is too late to apply--

<property name= "Minidle" value= "1"/>

</bean>

??

Why use a data source this mechanism

??

Reduce frequent and database establishment Connection and Disconnect, the data source starts to establish 3 connections, the equivalent of a connection pool, buffer pool, if you need to connect, directly from the connection pool, more than 3 and then establish a connection with the database

??

If the maximum number is exceeded, wait for the

??

Configure Sessionfactory

??

<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >

<!-- setting up data sources-

<property name= "DataSource" ref= "DataSource"/>

<!-- took over the Hibernate Object Mapping file--

<property name= "Mappingresources" >

<list>

<value>com/hsp/domain/Employee.hbm.xml</value>

</list>

</property>

<property name= "Hibernateproperties" >

<value>

Hibernate.dialect=org.hibernate.dialect.oracledialect

???????? hibernate.hbm2ddl.auto=update

Hibernate.show_sql=false

Hibernate.format_sql=false????????

</value>

</property>

</bean>

??

and Employee.hbm.xml file

??

<class name= "Employee" table= "Employee" >

<!-- primary Key Policies --

<id name= "id" type= "Java.lang.Integer" >

<generator class= "native"/>

</id>

<property name= "Email" type= "java.lang.String" >

<column name= "Email" length= "/>"

</property>

??

To test

??

Written in the main function of Test.java

??

Sessionfactory Sf=ac.getbean ("Sessionfactory");

Session s=sf.opensession ();

Employee Employee=new employee (" Zi Liu ", "[email protected]", "145", 1,new java.util.Date (), 234.56f);

Transaction tx=s.begintransaction ();

S.save (employee);

Tx.commit ();

??

Query the database, get

??

??

??

??

Spring Employee Management System SSH 1

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.