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

學無先后,達者為師

網站首頁 編程語言 正文

Mybatisplus的增刪改查

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

01 Mybatis-plus的CRUD

  • Mybatis-plus實現了單表的增刪改查

  • create 添加數據 read讀取數據 update 修改數據 delete刪除數據

02 簡單的mybatis-plus方法

  • 測試類

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

1.增加insert

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

2.刪除delete

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

3.修改update

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

4.查找select

// 查找對應數據庫所有數據
	List<Category> categories=iCategoryService.list();
// 根據表主鍵查詢一條數據
	Category category=iCategoryService.getById(new Long(100));
// 根據數據庫批量查詢
     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

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