MyBatis中的mapping.xml和dao層介面組合使用
阿新 • • 發佈:2019-01-29
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