zoukankan      html  css  js  c++  java
  • 自定义 mapper

    1. 定义一个接口

    public interface ItemMapper {
        
        List<Item> getItemList();
    }

    2. 编写  xml  文件 ,  将sql 语句填入进去,  id为接口中的方法名称,  返回类型为自定义的pojo对象

    <?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.sys.search.mapper.ItemMapper" >
        <select id="getItemList" resultType="com.sys.search.pojo.Item">
            select a.id,a.title,a.sell_point,a.price,a.image,b.`name` category_name,c.item_desc from tb_item a LEFT JOIN tb_item_cat b ON a.cid=b.id LEFT JOIN tb_item_desc c ON a.id=c.item_id;
        </select>
    </mapper>

    3. applicationContext中配置加载 mapper 代理对象

    <!-- 配置扫描包,加载mapper代理对象 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.sys.rest.mapper,com.sys.search.mapper"></property>
        </bean>
  • 相关阅读:
    拟阵学习笔记
    HNOI 2016 解题报告
    HNOI 2015 解题报告
    一类动态规划问题状态的简化
    组合数学学习笔记
    简单多项式学习笔记
    基础线代学习笔记
    后缀数据结构学习笔记
    图论学习笔记
    AT3673 [ARC085D] NRE 题解
  • 原文地址:https://www.cnblogs.com/redhat0019/p/10192049.html
Copyright © 2011-2022 走看看