MyBatis framework notes 02

In the last lecture, we defined two query statements in UserMapper.xml: findById and findAll, and correspondingly defined two abstract methods in the UserMapper interface: findById(int id) and findAll().
(1) Introduce the result mapping element in the mapper configuration file.
If the column name of the table is inconsistent with the attribute name of the entity, for example, the register_time field of the table corresponds to the registerTime attribute of the entity class, we need to define the resultMap. Of course, it can also be defined if they are consistent.
Insert picture description here
(1) Run the testFindAll() test method
Insert picture description here
in the test class TestUserMapper, and view the results Add the test method testFindByName() in the test class TestUserMapper
Insert picture description here

Run the test method testFindByName() and view the results.
Insert picture description here
3. Insert table records
(1) Add a mapping statement in UserMapper.xml-insert
Insert picture description here
(2) Add a test method testInsert() in the test class TestUserMapper
Insert picture description here
(3) Run the test method testestInsert() , View the result
Insert picture description here
4. Update the table record
(1) Add the mapping statement -updata in UserMapper.xml
Insert picture description here
(2) Add the test method testUpdate() in the test class TestUserMapper
Insert picture description here
(3) Run the test method testUpdate(), view the result
Insert picture description here
5. Delete Table record
(1) Add the mapping statement -deleteById in UserMapper.xml
Insert picture description here
(2) Add the test method testDeleteById() in the test class TestUserMapper Insert picture description here
(3) Run the test method testDeleteById() and view the result
Insert picture description here

Guess you like

Origin blog.csdn.net/triet/article/details/114524063