Spring uses jdbc

For some of them

@Repository(value="userDao")

The annotation is to tell Spring to let Spring create a UserDaoImpl instance named "userDao".

When the Service needs to use the UserDaoImpl instance named "userDao" created by Spring, you can use the @Resource (name = "userDao") annotation to tell Spring that Spring can inject the created userDao into the Service.

@Autowired annotation, it can annotate class member variables, methods and constructors to complete the work of automatic assembly. Use @Autowired to eliminate set and get methods

 

 Adapting this in xml is an automatic scan package.

1. First establish the data source: db.properties

jdbc.user=root
jdbc.password=cdcssds
jdbc.jdbcUrl=ssss
jdbc.initPoolSize=?
dengdeng 
View Code

2. Create the spring configuration file afterwards

Then import the newly created data source:

 

 Then configure the data source of c3p0 (connected with the one above): the specific statement is as follows: the first four are necessary. A few of them are themselves

 

Also added. It can be multiple.

3. Create junit test case afterwards

 This is for testing. Make sure you can connect to the database. The main statement in this file is: first create the bean xml object

 

 

Test it like this after the meeting. After judging that the database is connected, other related operations are performed. Just click run as junit

 

4. After that, configure the jdbcTemple of spring in the xml file

 

 5. After that, write a statement in the test file of the Lever to test it again:

Single-handed related operations

 

 

Batch related operations

 

 The last parameter is the list type of Object []: because a piece of data requires an array of Object. Multiple data requires multiple arrays of Object.

After that, the data is searched from the database. Save to object for storing records.

 

 

 

 

The employee is a class object written by myself.

Afterwards, the relevant explanation of the corresponding amount is as follows:

 

 Afterwards, a set of objects is queried. Both return is a collection of objects of the class.

 

What happens afterwards is to get the value of a single column. Or do statistical inquiry :::

 

The code used during development is as follows:

 

Guess you like

Origin www.cnblogs.com/dazhi151/p/12686644.html