日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

Mybatisplus的增刪改查

作者:宣布無人罪 更新時(shí)間: 2023-12-18 編程語言

01 Mybatis-plus的CRUD

  • Mybatis-plus實(shí)現(xiàn)了單表的增刪改查

  • create 添加數(shù)據(jù) read讀取數(shù)據(jù) update 修改數(shù)據(jù) delete刪除數(shù)據(jù)

02 簡(jiǎn)單的mybatis-plus方法

  • 測(cè)試類

    public class Category {
        @TableId
        private Long categoryId;
        private String categoryName;
        private String categoryPicture1;
        private String categoryPicture2;
    }
    

1.增加insert

// 向數(shù)據(jù)庫插入一條記錄
 	Category category=new Category();
   	category.setCategoryName("電腦");
    Long num=new Long(100);
    category.setCategoryId(num);
    boolean add=iCategoryService.save(category);

2.刪除delete

// 根據(jù) ID 刪除
	Category category=new Category();
   category.setCategoryName("機(jī)器人");
   Long num=new Long(100);
   category.setCategoryId(num);
   boolean delete=iCategoryService.removeById(category);
//或者直接傳主鍵也是可以刪除的
   boolean delete=iCategoryService.removeById(new Long(100));

3.修改update

//根據(jù)ID修改		
	Category category=new Category();
    category.setCategoryName("機(jī)器人");
    Long num=new Long(100);
  	category.setCategoryId(num);
  	 boolean update=iCategoryService.updateById(category);

4.查找select

// 查找對(duì)應(yīng)數(shù)據(jù)庫所有數(shù)據(jù)
	List<Category> categories=iCategoryService.list();
// 根據(jù)表主鍵查詢一條數(shù)據(jù)
	Category category=iCategoryService.getById(new Long(100));
// 根據(jù)數(shù)據(jù)庫批量查詢
     LinkedList<Long> list = new LinkedList<>();
     list.add(new Long(1));
     list.add(new Long(2));
     list.add(new Long(3));
     List<Category> categoryList=iCategoryService.listByIds(list);

原文鏈接:https://blog.csdn.net/2302_77182979/article/details/134471698

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新