栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Springboot 快速集成 MyBatis-Plus

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Springboot 快速集成 MyBatis-Plus

Springboot 快速集成 MyBatis-Plus
  1. 引入依赖
        
            com.baomidou
            mybatis-plus-boot-starter
            3.4.2
        
        
            com.baomidou
            mybatis-plus-extension
            3.4.2
        
  1. 测试实体类
@Data
public class FacePerson implements Serializable {

    private Long id;
    private String name;
    private byte[] feature;
    private Long imageId;
    private String imageUrl;
}

  1. Service 接口和 ServiceImpl
public interface FacePersonService {

    List list();

    int add(FacePerson facePerson);

    IPage page(Page page, FacePersonQuery query);

    int delete(Long id);
}
@Service
public class FacePersonServiceImpl implements FacePersonService {

    @Autowired
    private FacePersonMapper facePersonMapper;

    @Override
    public List list() {
        return facePersonMapper.selectList(null);
    }

    @Override
    @Transactional
    public int add(FacePerson facePerson) {
        return facePersonMapper.insert(facePerson);
    }

    @Override
    public IPage page(Page page, FacePersonQuery query) {
        return facePersonMapper.page(page,query);
    }

    @Override
    public int delete(Long id) {
        return facePersonMapper.deleteById(id);
    }
}
  1. Mapper接口和xml
public interface FacePersonMapper extends baseMapper {

    IPage page(Page page, @Param("param")FacePersonQuery query);
    
}

xml 放于默认位置 resource/mapper 下





    
        
        
        
        
        
    

    


  1. 加入@MapperScan注解,指定mapper接口所在包
@SpringBootApplication
@MapperScan(basePackages = {"top.yinjinbiao.arcface.mapper"})
public class ArcfaceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ArcfaceApplication.class, args);
    }
}
  1. application.yml中加入配置
mybatis-plus:
  mapper-locations: classpath*:/mapper/*Mapper.xml
  typeAliasesPackage: top.yinjinbiao.arcface.domains.entity
  global-config:
    db-config:
      id-type: auto
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/274955.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号