MyBatis返回map数据
(1)接口中编写方法
//单行
public Map<String, Object> getEmpReturnMap(Integer id); //多行
@MapKey("id")
public Map<Integer, Emp> getEmpReturnMaps(String lastName);
(2)编写Mapper文件
MyBatis框架为Map起别名叫map
<!-- public Map<String, Object> getEmpReturnMap(Integer id); -->
<select id="getEmpReturnMap" resultType="map">
select id,last_name lastName,gender geder,email from Emp where id like #{id }
</select> <!-- public Map<String, Object> getEmpReturnMaps(String lastName); -->
<select id="getEmpReturnMaps" resultType="com.eu.bean.Emp">
select id,last_name lastName,gender geder,email from Emp where last_name like #{lastName }
</select>
(3)编写测试
@Test
public void testMapperReMap() throws IOException {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
//1.获取到sqlsession 不会自动提交数据
SqlSession openSession = sqlSessionFactory.openSession();
EmpDao mapper = openSession.getMapper(EmpDao.class); Map<Integer, Emp> empReturnMaps = mapper.getEmpReturnMaps("%e%");
System.out.println(empReturnMaps); //手动提交数据
openSession.commit();
openSession.close();
}
MyBatis返回map数据的更多相关文章
- mybatis返回map类型数据空值字段不显示的解决方法
在日常开发中,查询数据返回类型为map,数据库中有些自动值为null,则返回的结果中没有值为空的字段,则如何显示值为空的字段呢? Spring boot + MyBatis返回map中null值默认不 ...
- mybatis返回map结果集
今天突发奇想,想用mybatis返回一个map结果集,结果我就整了一下午,不过终于解决了 1.如果你确定返回的数据只有一条,你可以这样整 xml中: <select id="searc ...
- 用Mybatis返回Map,List<Map>
返回Map,Mybatis配置如下 : <select id="getCountyHashMap" resultType="java.util.HashMap&qu ...
- MyBatis 返回 Map 字段丢失问题
问题现象 执行存储过程返回 Map 集合数据,发现有字段丢失情况,仔细研究发现丢失的字段值都为 NULL. 解决办法1: 在查询 SQL 语句中增加 NULL 判断函数 MSSQL: isnull(字 ...
- Mybatis,返回Map的时候,将Map内的Key转换为驼峰的命名
每次使用mybatis的时候,简单的连表查询,用Map接收的时候,都是像DB定义的字段一样,类似以下 student_name,student_id,没有转换为驼峰,但是又不能因为这一个定义一个jav ...
- mybatis返回map类型数据空值字段不显示(三种解决方法)
转http://blog.csdn.net/lulidaitian/article/details/70941769 一.查询sql添加每个字段的判断空 IFNULL(rate,'') as rate ...
- MyBatis返回Map键值对数据
List<Map<String, String>> getMtypeList(); <select id="getMtypeList" resultT ...
- MyBatis 返回新增数据的自增id
<insert id="save" parameterType="Vote" useGeneratedKeys="true" keyP ...
- MyBatis 返回Map<String,Object>类型
<!-- 导出所有数据 --> <select id="exportAll" resultMap="map"> SELECT t1.ME ...
随机推荐
- Object Detection / Human Action Recognition 项目
https://towardsdatascience.com/real-time-and-video-processing-object-detection-using-tensorflow-open ...
- centos 7.2 安装mongodb 3.4.4免编译
/根目录下: 获取命令: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.4.tgz 解压命令: tar zvxf mon ...
- LeetCode刷题-005最长回文子串
给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为1000.示例 1:输入: "babad"输出: "bab"注意: "ab ...
- springboot自定义配置信息读取
在properties配置文件加入自定义配置例如: zxgl.detail.url=http://*****/zxgl-web/news/viewNewsIndexDetail.do?id= #资讯t ...
- nginx做80端口转发
server { server_name zjrzb.cn listen 80; location / { proxy_pass http://127.0.0.1:8090; proxy_set_he ...
- Linux中查看端口占用情况
1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口的使用情况: # lsof -i:8000 2.netstat -tunlp | grep 端口号,用于查看指定的端口号的进 ...
- pmi-ACP考试知识点梳理(部分)
敏捷宣言 个体和互动 高于流程和工具 工作的软件 高于详尽的文档 客户合作 高于合同谈判 响应变化 高于遵循计划 十二条敏捷原则 1 我们最重要的目标,是通过持续不断地及早交付有价值的软件使客户满意. ...
- 微信小程序开发学习(一)
一.各种JSON配置 1.小程序配置app.json 为小程序全局配置,包括所有页面路径.界面表现.网络超时时间.底部tab等,类比APP开发中manifest配置. 2.工具配置project.co ...
- margin合并和浮动
1.父子元素margin塌陷问题子元素设置margin-top作用于父元素时, 会产生margin合并问题. 解决方法是: 给父元素的::before伪元素设置为display:table属性, 其中 ...
- 二级导航 js
$(function(){ $(".classify dl dd").mouseover(function(){ $(this).addClass("on"); ...