zoukankan      html  css  js  c++  java
  • mybatis框架的mapper.xml配置

    <?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">
    <!-- namespace命名空间,为了对sql语句进行隔离,方便管理 ,mapper开发dao方式,使用namespace有特殊作用 -->
    <mapper namespace="com.test.dao.UserMapper">
    <!-- 配置sql语句 -->
    <!-- 根据用户ID进行查询
    select 中的id是
    select * from userss where id=#{id} 这个sql语句是从plsqlz
    parameterType指定参数输入类型
    #{}表示一个占位符号
    #{ID} 里面的ID表示的是输入参数 参数的名字是ID 如果输入参数是Java简单类型 可以使用该方式
    resultType:指定sql语句的输出结果类型 这里的是Java对象
    -->
    <select id="findUserById" parameterType="int" resultType="entity.User">
    select * from userss where id=#{id}
    </select>

    <!-- 包装类 -->
    <select id="findUserList" parameterType="entity.UserQueryVo" resultType="entity.UserCoustom">
    <!-- userCoustom这个应该和UserQueryVo中的userCoustom属性保持一致 -->
    Select * From userss Where sex=#{userCoustom.sex} And username Like '%${userCoustom.username}%'
    </select>
    <!-- 返回简单类型 -->
    <select id="findUserCount" parameterType="entity.UserQueryVo" resultType="java.lang.Integer">
    Select count(*) From userss Where sex=#{userCoustom.sex} And username Like '%${userCoustom.username}%'
    </select>

    <!-- resultType的高级映射
    Select id id,username u,sex s From userss;
    id表示查询结果的唯一标识
    type resultMap映射的Java类型 可以使用别名
    -->
    <resultMap type="entity.User" id="userResultMap">
    <!-- id 表示查询的主键
    column 查询出来的列名
    property pojo中的属性名
    -->
    <id column="id_" property="id"/>
    <!-- result是对普通列的映射 -->

    <result column="username_" property="username"/>
    <result column="sex_" property="sex"/>
    <result column="address_" property="address"/>
    </resultMap>

    <select id="findUserByResultMap" parameterType="int" resultMap="userResultMap">

    Select id id_,username username_,sex sex_, address address_ From userss Where id=#{value}
    </select>


    </mapper>

    在sqlmapconfig.xml文件中配置好mapper.xml的映射文件

    <!-- 加载mapper.xml -->
    <mappers>
    <!-- mapper中的resource是实体类的映射文件的路径 -->

    <mapper resource="com/test/dao/UserMapper.xml" />
    </mappers>

    确认配置没有错误后  去配置mapper.xml文件

    <!-- namespace命名空间,为了对sql语句进行隔离,方便管理 ,mapper开发dao方式,使用namespace有特殊作用 -->
    <mapper namespace="com.test.dao.UserMapper">

    注意namespace指定的是所操作的实体类所对应的路径

  • 相关阅读:
    UVA 1025 A Spy in the Metro DP水题
    ZOJ 3814 Sawtooth Puzzle BFS
    ZOJ 3816 Generalized Palindromic Number
    UVA 10859 Placing Lampposts 树形DP
    UVA 11825 Hackers' Crackdown 状压DP
    POJ 2887 Big String 线段树 离线处理
    POJ 1635 Subway tree systems Hash法判断有根树是否同构
    BZOJ 3110 k大数查询 & 树套树
    sdoi 2009 & 状态压缩
    来自于2016.2.24的flag
  • 原文地址:https://www.cnblogs.com/cpx123/p/7647448.html
Copyright © 2011-2022 走看看