spring boot mybatis-plus操作实践

发布时间:2024年01月12日

1、先建一个数据表实体类

package com.qilaike.system.domain;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.qilaike.common.annotation.Excel;

public class SysDept 
{
    private static final long serialVersionUID = 1L;

    /** 用户ID */
    private Long technicianId;

    /** 门店ID */
    private Long deptId;
    @Excel(name = "门店")
    private String deptName;

    /** 用户账号 */
    @Excel(name = "用户账号")
    private String userName;

    /** 用户昵称 */
    @Excel(name = "用户昵称")
    private String nickName;
    
    /** 姓名 */
    @Excel(name = "姓名")
    private String idName;
}

2、service目录下新建接口IDeptService,然后扩展mp的IService

package com.qilaike.system.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.qilaike.common.core.domain.entity.SysDept;

public interface IDeptService extends IService<SysDept>{
}

3、service目录的impl目录下新建类 DeptServiceImpl,扩展mp的ServiceImpl,实现接口IDeptService,然后注册@Service 注解

package com.qilaike.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qilaike.common.core.domain.entity.SysDept;
import com.qilaike.system.mapper.DeptMapper;
import com.qilaike.system.service.IDeptService;
import org.springframework.stereotype.Service;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, SysDept> implements IDeptService {
}

4、DeptMapper 接口需要扩展mp的BaseMapper接口

public interface SysDeptMapper extends BaseMapper<SysDept>
{
}

5、调试一下看看是否可以使用

// 部门
LambdaQueryWrapper<SysDept> departmentsLambdaQueryWrapper=new LambdaQueryWrapper<>();
departmentsLambdaQueryWrapper.eq(SysDept::getParentId, deptId);
List<OrgTreeVo> orgTreeVos = new LinkedList<>();
deptService.list(departmentsLambdaQueryWrapper).forEach(dept -> {
    orgTreeVos.add(OrgTreeVo.builder()
            .id(dept.getDeptId())
            .name(dept.getDeptName())
            .selected(false)
            .type("dept")
            .build());
});
文章来源:https://blog.csdn.net/l2x1314258/article/details/135554333
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。