mybatis-plus批處理IService的實現(xiàn)示例
一、pom文件引入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.1.tmp</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>3.3.1.tmp</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
二、Controller層
@RequestMapping("/user") @RestController public class UserController { @Autowired UserInfoService userInfoService; @RequestMapping("/add") public void addUser() { userInfoService.addUser(); } }
三、IService層(此處請確保繼承的是 mybatisplus下的 IService,上述的UserInfoEntity為實體類)
import com.baomidou.mybatisplus.extension.service.IService; import com.entity.UserInfoEntity; public interface UserInfoService extends IService<UserInfoEntity>{ public void addUser(); }
四、ServiceImpl(UserInfoDao和UserInfoEntitty分別為業(yè)務對應的UserEntityDao接口和UserInfoEntitty實體類)
@Service public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService{ @Override public void addUser() { Random r=new Random(100); String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random=new Random(); Set<UserInfoEntity> entityList=new HashSet<UserInfoEntity>(); for(int i=0;i<1000000;i++) { UserInfoEntity entity=new UserInfoEntity(); entity.setAge(r.nextInt()); int number=random.nextInt(62); entity.setName(""+str.charAt(number)); entity.setEvaluate("good"); entity.setFraction(r.nextLong()); entityList.add(entity); } this.saveBatch(entityList); }
五、entity層
@TableName("user_info")//@TableName中的值對應著表名 @Data public class UserInfoEntity { /** * 主鍵 * @TableId中可以決定主鍵的類型,不寫會采取默認值,默認值可以在yml中配置 * AUTO: 數(shù)據(jù)庫ID自增 * INPUT: 用戶輸入ID * ID_WORKER: 全局唯一ID,Long類型的主鍵 * ID_WORKER_STR: 字符串全局唯一ID * UUID: 全局唯一ID,UUID類型的主鍵 * NONE: 該類型為未設置主鍵類型 */ @TableId(type = IdType.AUTO) private Long id; /** * 姓名 */ private String name; /** * 年齡 */ private Integer age; /** * 技能 */ private String skill; /** * 評價 */ private String evaluate; /** * 分數(shù) */ private Long fraction;
六、Mapper接口層
@Mapper public interface UserInfoDao extends BaseMapper<UserInfoEntity>{ }
到此這篇關于mybatis-plus批處理IService的實現(xiàn)示例的文章就介紹到這了,更多相關mybatis-plus批處理IService內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
為何修改equals方法時還要重寫hashcode方法的原因分析
這篇文章主要介紹了為何修改equals方法時還要重寫hashcode方法的原因分析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06基于SpringBoot創(chuàng)建Web頁面并熱更新的操作步驟
SpringBoot是一個用于快速開發(fā)單個微服務的框架,它基于 Spring 框架,簡化了Spring應用的初始化過程和開發(fā)流程,本文給大家介紹了如何基于SpringBoot創(chuàng)建Web頁面并熱更新,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-11-11微信js sdk invalid signature簽名錯誤問題的解決方法分析
這篇文章主要介紹了微信js sdk invalid signature簽名錯誤問題的解決方法,結合實例形式分析了微信簽名錯誤問題相關解決方法,需要的朋友可以參考下2019-04-04