MyBatis中的mapping.xml和dao层接口组合使用

Springboot与mybatis整合

在application.properties文件中

mybatis.mapper-locations=classpath*:mapping/*.xml

mybatis中的mapping.xml的与Dao层组合使用

bean实体类

(@Data相当于给属性给设置set和get,相关资料 https://blog.csdn.net/u010931123/article/details/80510849

@Data

@AllArgsConstructor
@NoArgsConstructor
public class FjsTic {    private String spchCode;    private String settMonth;    private String ticType;    private String ticAccAddress;    private String ticAccP;    private String ticTelephone;    private String companyName;    private String taxpayerNum;    private String taxpayerAddress;    private String taxpayerTelephone;    private String taxpayerBankname;    private String taxpayerAccountname;    private String taxpayerAccountno; }


FjsTicMapper.xml(位置为src/main/resource/mapping/FjsTicMapper.xml)


说明:

resultMap中的result中的property与实体类属性一致,column中的数据库表的字段值一致

select中的id与Dao层中的方法一样

parameterType参数类型

<?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.baidu.test.dao.FjsTicDao">

    <resultMap id="fjsTicResultMap" type="com.baidu.test.entity.FjsTic">
        <result property="spchCode" column="spch_code"/>
        <result property="settMonth" column="sett_month"/>
        <result property="ticType" column="tic_type"/>
        <result property="ticAccAddress" column="tic_acc_address"/>
        <result property="ticAccP" column="tic_acc_p"/>
        <result property="ticTelephone" column="tic_telephone"/>
        <result property="companyName" column="company_name"/>
        <result property="taxpayerNum" column="taxpayer_num"/>
        <result property="taxpayerAddress" column="taxpayer_address"/>
        <result property="taxpayerTelephone" column="taxpayer_telephone"/>
        <result property="taxpayerBankname" column="taxpayer_bankname"/>
        <result property="taxpayerAccountname" column="taxpayer_accountname"/>
        <result property="taxpayerAccountno" column="taxpayer_accountno"/>
    </resultMap>
<select id="queryFjsTicExport" parameterType="String" resultMap="fjsTicResultMap">
        SELECT
          *
        FROM
          agm_fjs_tic
        WHERE file_id=#{fileId}
    </select>
</mapper>


Dao层:

@Mapper
public interface FjsTicDao {

    List<FjsTic> queryFjsTicExport(@Param("fileId") String fileId);







@AllArgsConstructor
@NoArgsConstructor

猜你喜欢

转载自blog.csdn.net/u010931123/article/details/80665435