Springboot 快速集成 MyBatis-Plus

Springboot 快速集成 MyBatis-Plus

  1. 引入依赖
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-extension</artifactId>
            <version>3.4.2</version>
        </dependency>
  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<FacePersonDTO> page(Page<FacePersonDTO> 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<FacePersonDTO> page(Page<FacePersonDTO> 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<FacePerson> {

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

xml 放于默认位置 resource/mapper 下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="top.yinjinbiao.arcface.mapper.FacePersonMapper">

    <resultMap id="BaseResultMap" type="top.yinjinbiao.arcface.domain.entity.FacePerson">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="feature" jdbcType="BLOB" property="feature" />
        <result column="image_id" jdbcType="BIGINT" property="imageId"></result>
        <result column="image_url" jdbcType="VARCHAR" property="imageUrl"></result>
    </resultMap>

    <select id="page" resultType="top.yinjinbiao.arcface.domain.dto.FacePersonDTO">
        select
        t.id,
        t.name,
        t.image_url from face_person t
        <where>
            <if test="param.name != null ">
                and t.name like concat('%', #{param.name,jdbcType=VARCHAR}, '%')
            </if>
        </where>
    </select>

</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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值