依赖
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