第一、一对一:

<resultMap type="com.zktx.platform.entity.tb.Module" id="BaseResultMap">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="class_name" jdbcType="VARCHAR" property="class_name"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="priority" jdbcType="INTEGER" property="priority"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="url" jdbcType="VARCHAR" property="url"/>
<result column="parent_id" jdbcType="INTEGER" property="parent_id"/>
<association column="parent_id" property="parent_Module" select="selectById"></association>
</resultMap> <select id="queryList" resultMap="BaseResultMap">
select * from tb_module m1 left join tb_module m2 on m1.parent_id =m2.id
</select>
<select id="selectById" parameterType="java.lang.Integer" resultType="com.zktx.platform.entity.tb.Module">
select * from tb_module where id=#{parent_id}
</select>

对应java的dao层代码:

List<Module> queryList();

第二、批量删除

<delete id="deleteByIds" parameterType="java.util.List">
delete from tb_module where id in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item,jdbcType=INTEGER}
</foreach>
</delete>

对应的java的dao层代码:

void deleteByIds(List<Integer> ids);

 第三、批量增加

<insert id="insertBatch" parameterType="java.util.List">
insert into tb_role_permission (permission_id,role_id) VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.permission_id,jdbcType=INTEGER},#{item.role_id,jdbcType=INTEGER})
</foreach>
</insert>

对应的java代码:

void insertBatch(List<RolePermission> rolePermissions);

第四、插入数据,返回id

<insert id="insertSelective" parameterType="com.zktx.platform.entity.tb.Module" >
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>

insert into tb_module
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="class_name!=null">
class_name,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="class_name!=null">
#{class_name,jdbcType=VARCHAR},
</if>
</trim>
</insert>

java代码(返回的id在参数module中):

public void insertSelective(Module module) {
int id = moduleMapper.insertSelective(module);
if (id > 0) {
List<Permission> permissions = module.getPermissions();
if (null != permissions && permissions.size() > 0) {
for (Permission permission : permissions) {
permission.setModule_id(module.getId());
}
permissionMapper.insertBatch(permissions);
}
}
}

 第五、批量插入返回数据:

批量时,传入list,获取时类同单个,mybatis自动把自增的id装入list中的对象的id,mapper.xml写法如:

<insert id="insertBatch" parameterType="java.util.List"  useGeneratedKeys="true" keyProperty="id">
insert into tb_permission (name,sn,description,module_id) values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.name},#{item.sn},#{item.description},#{item.module_id})
</foreach>
</insert>

java代码:

// 添加对应权限
permissionMapper.insertBatch(permissions); // 为菜单权限增加角色
List<RolePermission> rolePermissions = new ArrayList<RolePermission>();
for (Permission permission : permissions) {
String[] roleidstr = roleids.split(",");
for (int i = 0; i < roleidstr.length; i++) {
RolePermission rolePermission = new RolePermission();
rolePermission.setPermission_id(permission.getId());
rolePermission.setRole_id(Integer.parseInt(roleidstr[i]));
rolePermissions.add(rolePermission);
} }

mybits 操作指南的更多相关文章

  1. 【项目管理】GitHub使用操作指南

    GitHub使用操作指南 作者:白宁超 2016年10月5日18:51:03> 摘要:GitHub的是版本控制和协作代码托管平台,它可以让你和其他人的项目从任何地方合作.相对于CVS和SVN的联 ...

  2. Tourist.js – 简单灵活的操作指南和导航插件

    Tourist.js 是一个基于 Backbone 和 jQuery 开发的轻量库,帮助你在应用程序创建简单易用的操作指南和导航功能.相比网站,它更适合用于复杂的,单页网站类型的应用程序.Touris ...

  3. HHKB MAC 配置指南 操作指南 快捷键

    1. 设备: mac电脑一台.hhkb键盘一个 2. 初级配置 (1)调节hhkb的模式为Macintosh模式:011001 (打开键盘侧边的滑盖,按照这个顺序调正) (2)Mac电脑安装官方驱动  ...

  4. 比较详细Python正则表达式操作指南(re使用)

    比较详细Python正则表达式操作指南(re使用) Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式.Python 1.5之前版本则是通过 regex 模块提供 E ...

  5. WEBUS2.0 In Action - 索引操作指南(2)

    上一篇:WEBUS2.0 In Action - 索引操作指南(1) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(1) 3. 添加.删除.撤销删除和修改文档 在WEBUS中要将 ...

  6. WEBUS2.0 In Action - 搜索操作指南 - (1)

    上一篇:WEBUS2.0 In Action - 索引操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(2) 1. IQueriable中内置的搜索功能 在Webus ...

  7. WEBUS2.0 In Action - 搜索操作指南 - (2)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(1) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(3) 2. 使用Query Query是所有查询的基类, 它一 ...

  8. WEBUS2.0 In Action - 搜索操作指南 - (3)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...

  9. WEBUS2.0 In Action - 搜索操作指南 - (4)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(3) 6. 搜索多个索引 为了提升性能, 我们可以从多个索引同时进行搜索, Webus.Search.MultiSearcher提供了相 ...

随机推荐

  1. 跳出双重for循环的案例__________跳出当前循环(continue out)

    package com.etc.operator; public class demo { public static void main(String[] args) { // break out; ...

  2. rabbit--消息持久化

    消息的可靠性是RabbitMQ的一大特色,那么RabbitMQ是如何保证消息可靠性的呢——消息持久化. 为了保证RabbitMQ在退出或者crash等异常情况下数据没有丢失,需要将queue,exch ...

  3. ie8及其以下版本兼容性问题之placeholder实现

    1. 普通浏览器下修改placeholder颜色 因为每个浏览器的CSS选择器都有所差异,所以需要针对每个浏览器做单独的设定. 示例: input::-webkit-input-placeholder ...

  4. 用Python+selenium打开IE浏览器和Chrome浏览器的问题

    这几天在学Python+selenium自动化,对三大浏览器Firefox,Chrome和IE都做了尝试,也都分别下载了对应的webdriver,如:geckodriver.chromedriver. ...

  5. 时序分析:串匹配-KMP算法

    图像处理与模式识别的教科书使用大量的章节来描述空域的模式识别方法.从图像底层特征提取.贝叶斯方法到多层神经网络方法,一般不讨论到对象随时间变化的情况,视频处理应用和在线学习方法使研究对象开始向时域延伸 ...

  6. 新书《计算机图形学基础(OpenGL版)》PPT已发布

    为方便有些老师提前备课,1-10章所有章节已发布到本博客中. 欢迎大家下载使用,也欢迎大家给我们的新书反馈与意见,谢谢!

  7. 面试回答问题要防范hr的陷阱

    面试技巧是大众化的,比较实在.在经历的各种面试中,最不容易防范的面试就是“拉呱”(山东方言,聊天的意思),这样子自己容易放松警惕. 看看下面的,就知道应该怎么应对这些“滑头”的HR! 1.我们为什么要 ...

  8. sessionStorage和localStorage存储的转换不了json

    先说说localStorage与sessionStorage的差别 sessionStorage是存储浏览器的暂时性的数据,当关闭浏览器下次再打开的时候就不能拿到之前存储的缓存了 localStora ...

  9. PAT_A1110#Complete Binary Tree

    Source: PAT A1110 Complete Binary Tree (25 分) Description: Given a tree, you are supposed to tell if ...

  10. [转载]ext4文件系统的delalloc选项造成单次写延迟增加的分析

    转载http://www.cnblogs.com/cobbliu/p/5603472.html 最近我们的服务进程遇到kill -15后处于Z的状态,变为了僵尸进程,经过/proc/{thread_i ...