In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "tk.mybatis to achieve uuid primary key generation method is what", in daily operation, I believe many people in tk.mybatis to achieve uuid primary key generation method is what problem there are doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "tk.mybatis to achieve uuid primary key generation method is what" doubts help! Next, please follow the small series to learn together!
introducing dependency tk.mybatis mapper-spring-boot-starter 2.0.2 1. Create an implementation class package com.xiaobu.base.entity; import tk.mybatis.mapper.genid.GenId; import java.util.UUID; /** * @author xiaobu * @version JDK1.8.0_171 * @date on 2019/3/27 11:37 * @description V1.0 */public class UUIdGenId implements GenId { @Override public String genId(String s, String s1) { return UUID.randomUUID().toString().replace("-",""); package com.xiaobu.entity; import com. xiaobu.base.entity.UUIdGenId;import lombok.Data;import tk.mybatis.mapper.annotation.KeySql; import javax.persistence.Id;import java.io.Serializable; /** * Function Description: Test uuid primary key generation * @author xiaobu * @date 2019/3/27 16:30 * @version 1.0 */@Datapublic class TbDemo1 implements Serializable { /** * */ @Id @KeySql(genId = UUIdGenId.class) private String id; /** * */ private String name; private static final long serialVersionUID = 1L;}3, Mapper class set into generic mapperpackage com.xiaobu.mapper; import com.xiaobu.base.mapper.MyMapper;import com.xiaobu.entity.TbDemo1;import org.apache.ibatis.annotations.Mapper; /** * Function Description: Continue to use Mapper * @author xiaobu * @date 2019/3/27 17:06 * @version 1.0 */@Mapperpublic interface TbDemo1Mapper extends MyMapper { }4, Test package com.xiaobu; import com.xiaobu.entity.TbDemo1;import com.xiaobu.mapper.TbDemo1Mapper;import org. junit.Test;import org.junit.runner.RunWith;import org. springframework.beans.factory.annotation.Autowired;import org. springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner; /** * @author xiaobu * @version JDK1.8.0_171 * @date on 2019/3/27 11:11 * @description V1.0 */@RunWith(SpringRunner.class)@SpringBootTestpublic class TbDemo1Test { @Autowired private TbDemo1Mapper tbDemo1Mapper; @Test public void insert(){ TbDemo1 tbDemo1 = new TbDemo1(); tbDemo1.setName("Test uuid generation"); tbDemo1Mapper.insert(tbDemo1); System.out.println("Add complete... "); }}
tk.mapper insertList is not supported, and the insertion method written by yourself is also not supported.
At this point, the study of "tk.mybatis to achieve uuid primary key generation method is what" is over, I hope to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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
© 2024 shulou.com SLNews company. All rights reserved.