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>
  • 相关阅读:
    web页面静态化与伪静态化
    mysql 优化之空间换时间
    QPS、PV、UV、RT 之间的关系
    接口
    MySQL 索引
    名词解释
    go 语言标识符
    Git版本控制与工作流
    Maven安装与配置
    IDEA工具使用说明
  • 原文地址:https://www.cnblogs.com/redhat0019/p/10192049.html
Copyright © 2011-2022 走看看