In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-09 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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.