mybatis 返回 Set
来源:互联网 发布:ubuntu修改镜像源 编辑:程序博客网 时间:2024/06/06 01:19
mybatis 返回 Set
相信大家平时用到返回List的情况比较多
一.那为什么要返回set集合
1.因为Set集合的特性就是 不能有重复数据,所以通常我们返回List之后还需要去掉重复数据 是不是很麻烦?可以直接返回Set直接帮我我们去掉重复数据(记得要重写实体类的equals和hashCode 这两个方法)
下面是测试代码:
1:实体类 记得要重写实体类的equals和hashCode 这两个方法(这里只展示这两个方法)
@Overridepublic int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((b == null) ? 0 : b.hashCode()); result = prime * result + ((frequency == null) ? 0 : frequency.hashCode()); result = prime * result + ((ids == null) ? 0 : ids.hashCode()); result = prime * result + ((magnetism == null) ? 0 : magnetism.hashCode()); result = prime * result + ((reelNumber == null) ? 0 : reelNumber.hashCode()); result = prime * result + ((trademark == null) ? 0 : trademark.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MagnetizingCurveBH other = (MagnetizingCurveBH) obj; if (b == null) { if (other.b != null) return false; } else if (!b.equals(other.b)) return false; if (frequency == null) { if (other.frequency != null) return false; } else if (!frequency.equals(other.frequency)) return false; if (ids == null) { if (other.ids != null) return false; } else if (!ids.equals(other.ids)) return false; if (magnetism == null) { if (other.magnetism != null) return false; } else if (!magnetism.equals(other.magnetism)) return false; if (reelNumber == null) { if (other.reelNumber != null) return false; } else if (!reelNumber.equals(other.reelNumber)) return false; if (trademark == null) { if (other.trademark != null) return false; } else if (!trademark.equals(other.trademark)) return false; return true; }
2: .xml 配置文件
<select id="testFindSet" resultMap="BaseResultMap" > select <include refid="Base_Column_List" /> from ANALYSIS_MAGNETIZING_CURVE_BH where TRADEMARK = 'AA0182'</select>
<resultMap id="BaseResultMap" type="com.sgai.qgpam.analysis.entity.MagnetizingCurveBH" > <id column="SID" property="sid" jdbcType="DECIMAL" /> <result column="TRADEMARK" property="trademark" jdbcType="VARCHAR" /> <result column="REEL_NUMBER" property="reelNumber" jdbcType="VARCHAR" /> <result column="FREQUENCY" property="frequency" jdbcType="DECIMAL" /> <result column="MAGNETISM" property="magnetism" jdbcType="DECIMAL" /> <result column="B" property="b" jdbcType="DECIMAL" /> <result column="CREATED_DT" property="createdDt" jdbcType="TIMESTAMP" /> <result column="CREATED_BY" property="createdBy" jdbcType="VARCHAR" /> </resultMap>
3.mybatis接口
public Set<MagnetizingCurveBH> testFindSet();
4 junit测试类
@Testpublic void testFindSet(){ Set<MagnetizingCurveBH> list = magnetizingCurveBHMapper.testFindSet(); for (MagnetizingCurveBH m : list) { System.out.println(m); }}
5 console 结果展示
1 还没有重写equals和hashCode
2 重写之后
大家要注意 不重复equals和hashCode 还是会有重复数据呦
阅读全文
1 0
- mybatis 返回 Set
- Mybatis对有可能返回empty set的数据库查询结果进行操作
- mybatis 传递set集合
- Mybatis environment set up
- mybatis传set参数
- mybatis标签set
- MyBatis insert 返回主键
- mybatis返回List<Map>
- mybatis返回map实现
- mybatis返回List<domain>
- MyBatis返回主键
- mybatis返回类型
- mybatis返回list<Map>
- mybatis insert返回主键
- mybatis insert 返回值
- mybatis 返回主键
- MyBatis返回主键
- mybatis 自定义返回值
- 文件复制
- Java 8 中的 Streams API 详解
- The Same Game UVA 758/Uvalive 5423 大模拟 求最大联通块并清除
- Ubuntu部署基于Fabric的虚拟区块链服务
- 简历
- mybatis 返回 Set
- 大部分人最缺的其实是「认知」
- Lua 中,将全局函数声明为local的优缺点
- java.util.NoSuchElementException异常
- iOS第三方平台集成组件化
- 进程间的通信方式--信号、管道、消息队列、共享内存
- Python-笔趣阁小说下载
- Tomcat配置与常见问题
- 3parentNode小例子