In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains how to use the addition, deletion, modification and writing of Springboot+mybatis. The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the addition, deletion, alteration and writing of Springboot+mybatis.
New additions, deletions, modifications and queries
No Controller, no xml, just mapper and entity classes can replace the original controller-mapper-xml
Introduce dependency
In addition to the commonly used springboot-related dependencies, add the knife toolkit, which as a whole depends on the following
Implementation 'org.springframework.boot:spring-boot-starter-web' implementation' org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3'
/ / the toolkit made by the knife relies on (released to the central warehouse) compile 'red.lixiang.tools:sunshine-starter:1.0.1' / / here to facilitate testing, citing h3, in practice it can be replaced with mysql runtimeOnly' com.h3database:h3' to prepare the test table
Here, in order to facilitate the operation of the code, we directly introduce the H 3 database. The table structure and test data are as follows:
Drop table users if exists
Create table users (id int, name varchar (20)); insert into users (id, name) values ((select count (*) + 1 from users), 'XiaoDao'); insert into users (id, name) values ((select count (*) + 1 from users),' official account: java technology base'); insert into users (id, name) values ((select count (*) + 1 from users), 'Wechat: best396975802')
Write entity classes
There are two entity classes, one is the entity class corresponding to the database, and the other is that the query QC,QC encapsulates some general fields related to the query. Corresponding fields in the database:
Users:
Public class Users {/ / this field identifies the field @ SqlField private Long id; @ SqlField private String name that corresponds to the database.
/ / the get/set method is omitted here.
UsersQC:
/ / notice that BaseQCpublic class UsersQC extends BaseQC {is inherited here.
Private Long id; / / the QC annotations here are used on demand. For example, here, the identification name is a field @ QC (likeQuery = true) private String name that can be vaguely queried.
} to write the mapper file of mybatis / / you need to inherit BaseMapper, which encapsulates the basic addition, deletion, modification and query @ Mapper@Repositorypublic interface UsersMapper extends BaseMapper {
/ / this method needs to be overridden to initialize some cache @ Override default Class getMapperClass () {MybatisToolCache.cacheDomain ("users", Users.class,UsersQC.class)
Return UsersMapper.class;}} write the configuration file for spring
There is no separate configuration here, it is all the configuration of H3 database. In practice, it can be replaced with mysql database.
# configure database connection address spring.datasource.platform=h3# configuration database driver spring.datasource.driver-class-name=org.h3.Driver# configuration database user name spring.datasource.username=saspring.datasource.schema=classpath:test_scheme.sqlspring.datasource.data=classpath:test_data.sql thank you for reading, the above is the content of "how to add, delete, change, check and write Springboot+mybatis", after the study of this article I believe that you have a deeper understanding of how to use the addition, deletion, modification and writing method of Springboot+mybatis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Configure DHCP server on Cisco Router:--ip dhcp excluded-addres
© 2024 shulou.com SLNews company. All rights reserved.