mybatis中,namespace的作用

来源:互联网 发布:txt全本小说软件 编辑:程序博客网 时间:2024/06/08 03:24

在mybatis中,映射文件中的namespace是用于绑定Dao接口的,即面向接口编程。

当你的namespace绑定接口后,你可以不用写接口实现类,mybatis会通过该绑定自动
帮你找到对应要执行的SQL语句

ItemsCustomMapperxml:<?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="cn.itcast.ssm.mapper.ItemsMapperCustom" >   <!-- 定义商品查询的sql片段,就是商品查询条件 -->   <sql id="query_items_where">    <!-- 使用动态sql,通过if判断,满足条件进行sql拼接 -->    <!-- 商品查询条件通过ItemsQueryVo包装对象 中itemsCustom属性传递 -->        <if test="itemsCustom!=null">            <if test="itemsCustom.name!=null and itemsCustom.name!=''">                items.name LIKE '%${itemsCustom.name}%'            </if>        </if>   </sql>    <!-- 商品列表查询 -->    <!-- parameterType传入包装对象(包装了查询条件)        resultType建议使用扩展对象     -->    <select id="findItemsList" parameterType="cn.itcast.ssm.po.ItemsQueryVo"         resultType="cn.itcast.ssm.po.ItemsCustom">        SELECT items.* FROM items          <where>            <include refid="query_items_where"></include>        </where>    </select></mapper>
0 0
原创粉丝点击