resultMap

<?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的名字需要跟接口的类名一致 -->
<mapper namespace="cn.bdqn.dao.UserMapper">
<!-- 当数据库中的字段信息与对象的属性不一致时需要通过resultMap来映射 -->
<resultMap type="User" id="seachUserResult">
<result property="id" column="id"/>
<result property="userCode" column="userCode"/>
<result property="userName" column="userName"/>
<result property="roleId" column="roleId"/>
<result property="roleName" column="roleName"/>
</resultMap> <select id="count" resultType="int">
select count(1) from user
</select> <insert id="add" parameterType="User">
insert into user (userCode,userName,userPassword)
values (#{userCode},#{userName},#{userPassword})
</insert> <update id="update" parameterType="User">
update user set userCode=#{userCode},userName=#{userName},
userPassword=#{userPassword} where id=#{id}
</update> <delete id="delete" parameterType="User">
delete from user where id=#{id}
</delete> <select id="getUserList" resultType="User">
select * from user
</select> <select id="getUserListByRoleId" parameterType="Role" resultMap="seachUserResult">
select u.*,r.roleName as roleName from user u,role r where u.roleId = r.id and u.roleId = #{id}
</select> </mapper>

mybatis中的resultMap的更多相关文章

  1. mybatis中的resultMap与resultType、parameterMap与 parameterType的区别

    Map:映射:Type:Java类型 resultMap 与 resultType.parameterMap 与  parameterType的区别在面试的时候被问到的几率非常高,项目中出现了一个小b ...

  2. mybatis中的resultMap实际作用

    resultMap和resultType在实际的使用上完全可以进行替换,但是resultMap有比resultType更多的一个功能.我们先定义一个简单的resultMap例子 <resultM ...

  3. mybatis中resultMap引发的吐血bug

    简单的讲: 问题背景:如果在写mybatis中的resultMap时,不下心将resultMapde id写成映射接口的名字,会发生什么? 结论:单元测试进度条卡住但不报错, Tomcat运行不报错, ...

  4. Mybatis中输出映射resultType与resultMap的区别

    Mybatis中输出映射resultType与resultMap的区别 (原文地址:http://blog.csdn.net/acmman/article/details/46509375) 一.re ...

  5. 【mybatis深度历险系列】mybatis中的输入映射和输出映射

    在前面的博文中,小编介绍了mybatis的框架原理以及入门程序,还有mybatis中开发到的两种方法,原始开发dao的方法和mapper代理方法,今天博文,我们来继续学习mybatis中的相关知识,随 ...

  6. SpringBoot+MyBatis中自动根据@Table注解和@Column注解生成增删改查逻辑

    习惯使用jpa操作对象的方式,现在用mybatis有点不习惯. 其实是懒得写SQL,增删改查那么简单的事情你帮我做了呗,mybatis:NO. 没办法,自己搞喽! 这里主要是实现了通过代码自动生成my ...

  7. mybatis中的懒加载

    知识点:mybatis中的懒加载的使用 参考:https://www.cnblogs.com/ysocean/p/7336945.html?utm_source=debugrun&utm_me ...

  8. mybatis中resultMap配置细则

    resultMap算是mybatis映射器中最复杂的一个节点了,能够配置的属性较多,我们在mybatis映射器配置细则这篇博客中已经简单介绍过resultMap的配置了,当时我们介绍了resultMa ...

  9. MyBatis中resultType和resultMap的区别

    resultType和resultMap功能类似  ,都是返回对象信息  ,但是resultMap要更强大一些 ,可自定义.因为resultMap要配置一下,表和类的一一对应关系,所以说就算你的字段名 ...

随机推荐

  1. css自定义字体

    @font-face { font-family: 华文隶书; src: url( ../font/STLITI.eot ); /* IE */ src: url( ../font/STLITI.tt ...

  2. Sql Server 附加没有日志文件的数据库(.mdf)文件方法

    附加数据库,附加的时候会提醒找不到log文件 针对以上现象有两个写法的语句能解决: 写法一: USE MASTER; EXEC sp_detach_db @dbname = 'TestDB'; EXE ...

  3. [POJ3177]Redundant Paths(双联通)

    在看了春晚小彩旗的E技能(旋转)后就一直在lol……额抽点时间撸一题吧…… Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  4. Quartz.Net在windows服务中的使用

    写在前面 这几天在弄一个项目,需要定时抓取一些数据,当时也想直接用timer算了.因为之前也弄过这样的项目,但是一想,已经用过了,再去使用同一种思路,未免太乏味了.就换了一种新玩法.这里将之前看到的一 ...

  5. 【Moqui框架】Moqui连接各种类型的数据库

    Moqui连接mysql数据库 各种数据库的连接文本: -- Derby<datasource group-name="transactional" database-con ...

  6. Spring配置文件详解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotation-driven />

    <context:annotation-config/> 在基于主机方式配置Spring时,Spring配置文件applicationContext.xml,你可能会见<contex ...

  7. C语言中memset(void *s, char ch,unsigned n)用的用法

    将指针s所指的内存空间中前n为重置为字符c 程序例: #include <string.h> #include <stdio.h> #include <memory.h& ...

  8. sql-in和not in

    IN .NOT IN这个指令可以让我们依照一或数个不连续 (discrete) 的值的限制之内抓出数据库中的值 in和not in in:存在与...里面的 not in:不存在与..里面的 其指令语 ...

  9. mysql-分页查询方案

    一.直接使用limit最简单查询方法: , 在中小数据量的情况下,这样的SQL足够用了,唯一需要注意的问题就是确保使用了索引. 随着数据量的增加,页数会越来越多,查看后几页的SQL就可能类似: , 言 ...

  10. Spring-事物-不依赖应用服务器的开源JTA事物实现

    不依赖应用服务器的开源JTA事物实现JOTM和Atomikos Transactions JOTM 即基于Java开放事务管理器(Java Open Transaction Manager),实现JT ...