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>
  • 相关阅读:
    python分析log
    单词长度统计,字符数量统计直方图
    单词计数
    字符替换
    HP Mobile Center 1.01 Related System Requirements
    字符统计
    文件复制
    C语言,不是从hello world开始
    最近
    echarts Map(地图) 不同颜色区块显示
  • 原文地址:https://www.cnblogs.com/redhat0019/p/10192049.html
Copyright © 2011-2022 走看看