首页 > 其他分享 >springboot中mybatis-plus简单配置与使用

springboot中mybatis-plus简单配置与使用

时间:2022-10-08 15:48:24浏览次数:40  
标签:String name CreditFicoData plus mybatis public springboot

依赖

mybatis-plus与mybatis依赖不兼容,同时使用会导致报错

<dependency>
     <groupId>com.oracle</groupId>
     <artifactId>ojdbc6</artifactId>
      <version>${oracle.version}</version>
</dependency>
<dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>mybatis-plus-boot-starter</artifactId>
      <version>3.5.2</version>
</dependency>
            

数据库配置

这次使用AutoConfigure功能

添加的文件

service和mapper

FicoMapper

public interface FicoMapper extends BaseMapper<CreditFicoData> {

    CreditFicoData findbyName(String name);
}

FicoServiceImpl

@Service
public class FicoServiceImpl extends ServiceImpl<FicoMapper, CreditFicoData> implements IFicoService {
    @Override
    public CreditFicoData findbyfname(String name) {
        return baseMapper.findbyName(name);
    }
}

IFicoService

public interface IFicoService extends IService<CreditFicoData> {

    CreditFicoData findbyfname(String name);
}

FicoData.xml

<?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="com.example.demo.mapper.FicoMapper">
    <select id="findbyName" parameterType="String" resultType="com.example.demo.Entity.CreditFicoData">
        select * from T_CREDIT_FICO_C1_DATA where
        1 = 1
        <if test="name != null">
            and name = #{name,jdbcType=VARCHAR}
        </if>
    </select>
</mapper>

说明

自定义sql需要在4个文件中添加sql语句,否则默认sql只需添加接口文件

查询

使用service中的方法去查询sql

public String testMpDb(){
    List<CreditFicoData> ficoDatalist = ficoService.list(Wrappers.<CreditFicoData>lambdaQuery()
            .eq(CreditFicoData::getMoblie, "133***333"));
    String res = JSONArray.toJSONString(ficoDatalist);
    log.info(res);
    return res;
}

标签:String,name,CreditFicoData,plus,mybatis,public,springboot
From: https://www.cnblogs.com/yorkiiz/p/16769112.html

相关文章

  • SpringBoot实战派读书笔记---响应式编程
    1.什么是WebFlux?WebFlux不需要ServletAPI,在完全异步且无阻塞,并通过Reactor项目实现了ReactorStreams规范。WebFlux可以在资源有限的情况下提高系统的吞吐量和......
  • MDK收费,MDK报价,MDK价格,含MDK Pro和MDK Plus
    ​​https://store.developer.arm.com/...ware-tools/keil-mdk​​MDKEssential的1年费用如下:MDKPlus的1年费用如下:MDKPro的1年费用如下:而永久授权费用是不公开的:这几......
  • Springboot集成阿里云短信
    目录1前言2准备工作2.1了解流程2.2配置信息2.3短信签名和模板2.3.1签名2.3.2模板2.3.3存入数据库3SDK4集成Springboot4.1集成4.2测试5后记1前言​ 线上系......
  • Red Hat 64位安装oracle 客户端sqlplus
    1.首先下载以下两个安装包:oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpmoracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm下载路径:https://www.ora......
  • mybatis-plus 分页操作
    mybatis-plus分页操作通过username,email,address等参数查询分页//分页查询-mybatis-plus的方式@GetMapping("/page")publicIPage<User>findPage(@R......
  • SpringBootServletInitializer的作用
    https://blog.csdn.net/luckyzsion/article/details/81135438?spm=1001.2101.3001.6650.7&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendF......
  • 从SpringBoot启动,阅读源码设计
    目录一、背景说明二、SpringBoot工程三、应用上下文四、资源加载五、应用环境六、Bean对象七、Tomcat服务八、事件模型九、配置加载十、数据库集成十一、参考源码服务启......
  • SpringBoot加载自动配置类的流程
    自定义过starter的同学应该都知道,自动配置类需要用EnableAutoConfiguration注解修饰,并且需要将自动配置类配置在spring.factories中。但自动配置类是如何被SpringBoot加......
  • 整合springboot
    案例1@RestControllerpublicclassUserInfoHandler{/***编程式校验*@paramuserInfo*@return*/@GetMapping("/addUser")......
  • MyBatis的执行器
    Mybatis执行器种类Mybatis的执行器Executor分为三类简单执行器:SimpleExcutor可重用执行器:ReuseExcutor批量执行器:BatchExcutor配置:在Mybatis配置文件中配置执行器......