Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does springboot-mybatis use junit4 unit tests to start mybatis separately

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how springboot-mybatis uses junit4 unit tests to start mybatis separately". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how springboot-mybatis uses junit4 unit tests to start mybatis alone.

1. First, add mybatis test's jar package to pom.

Org.mybatis.spring.boot mybatis-spring-boot-starter-test 1.3.2 test

two。 Add unit test classes

/ / @ SpringbootTest@MybatisTest / / Cache mybatsitest annotation @ RunWith (SpringJUnit4ClassRunner.class) @ AutoConfigureTestDatabase (replace = AutoConfigureTestDatabase.Replace.NONE) / / this is to enable the self-configured data element, otherwise the virtual data source @ Rollback (false) / / this is rollback by default and will not be commit into the database. If changed to false, commitpublic class MapperTest {@ Resource Mapper mapper; @ Test public void testInsert () {Entity entity = new Entity () Entity.setAct ("res"); int insert = mapper.insert (entity); System.out.println (insert); System.out.println (entity.getId ());}

3. Mybatis annotated sql writing

@ Insert ({"insert into otp_statistics (ACT) VALUES (# {act})")) / / @ SelectKey (statement = "SELECT LAST_INSERT_ID ()", keyProperty = "id", resultType = Integer.class, before = false) / / returns the inserted id, put entity into the parameter @ Options (useGeneratedKeys = true, keyProperty = "id") / / can only be used in self-adding id, return the inserted id, and put entity into the parameter int insert (OtpStatisticsEntity entity) At this point, I believe you have a deeper understanding of "how springboot-mybatis uses junit4 unit tests to start mybatis separately". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report