首页 > 数据库技术 > 详细

用mybatis将SQL查询语句”select * from user”的封装为配置文件

时间:2017-12-17 20:33:58      阅读:269      评论:0      收藏:0      [点我收藏+]

用mybatis将SQL查询语句”select * from user”的封装为配置文件

定义一个xml映射文件,文件名见名知意。如user-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">

<mapper namespace="suibian">

      <!-- 定义查询语法的标签.

           id - 语法命名, 由数字,字母,_ 组成. 数字不作为开头字符.

           resultType - 定义结果类型. 代表一行数据对应一个什么java类型的对象.

       -->

      <select id="selectAllUsers" resultType="com.pojo.User">

           <!-- 标签体中,定义要执行的SQL语句. -->

           select * from tb_user

      </select>

      <select id="selectUserById" resultType="com.pojo.User">

           select ID, Name, user_name as username, PassWORd, age from tb_user where id = 1

      </select>

      <select id="selectUsers" resultType="com.pojo.User">

           <![CDATA[

           select * from tb_user where id > 100

           ]]>

      </select>

</mapper>   

用mybatis将SQL查询语句”select * from user”的封装为配置文件

原文:http://www.cnblogs.com/7758521gorden/p/8053055.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!