2-8 CRUD Demo 1 of Mybatis-Plus

Demonstrate the




addition, deletion and modification of the CRUD demo based on MyBatis-plus.

Inject our mapper

This is the interface inside MyBatis.

If you use Autowired this way if it is not recognized. Then backendUser will report an error here. Its own scanning will be a bit problematic.

BackendUser inherited from BackendCommonApplicationTests will report an error.

If you change to @Resource, you will not get an error. The effect is the same, but we don't want to let an error be reported below.

So why inherit BackednCommonApplicationTests? The premise of the following @Resource injection is that a Spring container is required. Spring can only use MoocBackendUserTMapper as a dependency injection.

The use of Junit requires two tags, RunWith and @SpringBootTest. These two tags are inheritable.


You don't need to write every class. Just need to inherit BackendCommonApplicationTests.

This is the entity class generated by MyBatis-Plus for us, and it corresponds to our table structure.

add


insert in BaseMapper. BaseMapper is a tool class created by MyBatis-Plus for us.

The additions, deletions and changes are encapsulated. 



The error is reported because the data source has not been changed





and executed again



select



Query list

Wrapper here refers to the condition. I will introduce it later.

The stream is output cyclically.


Stream is a new concept provided by jdk1.8.

 

End

 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/12678806.html