Detailed construction process of java + mybatis + MySQL development environment

Main construction process

1. pom. Mybatis and database dependency are added to the XML file. Here, MySQL is used:

2. Create the configuration file of mybatis under the classpath xml

3. Execute SQL to create databases and tables:

4. com. john. hbatis. model. User class:

User. In the path of COM / John / hbatis / model xml

5. Test class:

The environment above interactive data in the form of interface is built by using the general method of sqlsession and forced conversion, which has the problem of conversion security:

It can be solved by adding SQL statements to the interface. SQL statements are understood as the implementation of the interface:

1. Create a new interface class:

2. Modify user XML file to ensure that the namespace attribute value is the same as the fully qualified name of the interface, and the ID attribute value is the same as the interface method name:

3. Add a test method in mybatisbasictest class:

Attachment: the above implementation is to put the SQL statement in the XML file, and ensure that the interface can find the corresponding SQL statement in the XML through certain constraints; Another way is to interact with data through interface + annotation SQL:

1. Create a new interface class:

2. In configuration Add to the XML file:

Or add in the initialization statement:

3. Modify the above test method accordingly:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>