1 写数据模型
2 在启动类上标注解**@MapperScan**("com.keyou.dao")扫描dao包接口层
3在dao接口上配注解**@Repository**
3.1注解:在接口方法上写@select,@update
3.2xml:在yml文件中配置xml所在类路径,例如
mybatis:
mapper-locations: /mapper/basicQuery/*Dao.xml
type-aliases-package : com.keyou.domain.basicQuery
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.keyou.dao.basicQuery.CertificationCenterDao" >
# **namespace**将xml文件与相对应dao接口映射
下面写sql语句 比如
<select id = "listQueryDpcInfoDO" resultMap ="getListDpcInfoDO" >
select * from
(
SELECT A.*, ROWNUM RN
FROM ( select *
from DPCINFO
<where>
<if test="centerInputParam.province !=null">
province = #{centerInputParam.province }
</if>
<if test="centerInputParam.city !=null">
and city = #{centerInputParam.city}
</if>
<if test="centerInputParam.area !=null">
and county = #{centerInputParam.area}
</if>
<if test="centerInputParam.begindate !=null and centerInputParam.enddate !=null">
and to_char(time,'yyyy-mm-dd') between #{centerInputParam.begindate} and #{centerInputParam.enddate}
</if>
<if test="centerInputParam.cardNoOrName !=null">
and addr = #{centerInputParam.cardNoOrName}
</if>
</where>) A
<where>
<if test="pageSize !=null and pageIndex !=null" >
ROWNUM <= #{pageSize}*#{pageIndex}
</if>
</where>
)
<where>
<if test= "pageIndex >1">
RN >=(#{pageIndex}-1)*#{pageSize}
</if>
</where>
</select>
# “#”中的对象属性为数据模型的属性值
# id :接口方法与sql语句映射
<resultMap id="getListDpcInfoDO" type="com.keyou.domain.basicQuery.DpcInfoDO">
<id property="dpcinfoguid" column="DPCINFOGUID"/>
<result property="dpcid" column="DPCID"/>
<result property="addr" column="ADDR"/>
<result property="time" column="TIME"/>
<result property="province" column="PROVINCE"/>
<result property="city" column="CITY"/>
<result property="county" column="COUNTY"/>
<result property="ip" column="IP"/>
</resultMap>
接口方法传入的参数加注解@param例如
List<DpcInfoDO> listQueryDpcInfoDO(@Param("centerInputParam") CertificationCenterInputParamDTO centerInputParam ,@Param("pageSize")int pageSize ,@Param("pageIndex")int pageIndex);
springboot的 mybatis基本运行配置
猜你喜欢
转载自blog.csdn.net/phillip629/article/details/90742868
今日推荐
周排行