Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing CRUD Operations with MyBatis-Plus in Spring Boot

Tech Oct 12 13

// Retrieves generated ID after insertion Long generatedId = newUser.getUserId();


</div>Delete Operations
-----------------

<div>```
int deleteCount = userRepository.deleteById(userId);

List<long> userIds = Arrays.asList(101L, 102L);
int batchDeleteCount = userRepository.deleteBatchIds(userIds);

Map<string object=""> conditionMap = new HashMap<>();
conditionMap.put("status", "inactive");
int conditionalDelete = userRepository.deleteByMap(conditionMap);</string></long>

List ids = Arrays.asList(1001L, 1002L); List users = userRepository.selectBatchIds(ids);

Map queryParams = new HashMap<>(); queryParams.put("department", "engineering"); queryParams.put("active", true); List filteredUsers = userRepository.selectByMap(queryParams);


</div>Wrapper Queries
---------------

<div>```
QueryWrapper<useraccount> queryWrapper = new QueryWrapper<>();
queryWrapper.like("username", "admin")
           .eq("role", "ADMINISTRATOR");

List<useraccount> adminUsers = userRepository.selectList(queryWrapper);</useraccount></useraccount>

System.out.println("Current page: " + result.getCurrent()); System.out.println("Total records: " + result.getTotal()); System.out.println("Page count: " + result.getPages()); List currentPageData = result.getRecords();


</div>Service Layer Implementation
----------------------------

<div>```
public interface UserService extends IService<useraccount> {
    List<useraccount> findInactiveUsers();
}</useraccount></useraccount>
@Override
public List<useraccount> findInactiveUsers() {
    QueryWrapper<useraccount> query = new QueryWrapper<>();
    query.eq("active", false);
    return baseMapper.selectList(query);
}

}


</div></div>

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.