第一、一对一:

<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. Objective-C—— @Property详解

    实例变量:属性其实说直白点就是 ivar + setter + getter(实例变量+存取方法),不过在OC中属性多了字面量这一系列特殊关键字使得OC属性有些不同. 成员属性我们应该都使用过,比如现 ...

  2. mssql server 2005自动备份数据库

    (转) (1)启动[sql server Management Studio],在[对象资源管理器]窗口里选择[管理]——[维护计划]选项. 2)右击[维护计划],在弹出的快捷菜单里选择[维护计划向导 ...

  3. mysql 5.6 中 explicit_defaults_for_timestamp参数

    mysql 5.6 中 explicit_defaults_for_timestamp参数 一: 官方文档中关于explicit_defaults_for_timestamp参数说明如下: expli ...

  4. We wanted {"required":["value"]} and you sent ["text","value","id","sessionId"]

    重装python pycharm后再次执行以前执行没有问题的Appium脚本报错 We wanted {"required":["value"]} and yo ...

  5. 【转载】IDEA的这八条配置你一定要改!

    引言 坦白说,我很少写这种操作类型的文章.因为这种文章没啥新意,大家操作步骤肯定是一样的.然而,我答应了我的同事小阳,给她出一篇!毕竟人家打算从Eclipse转IDEA了,于是以示鼓励,写一篇给她!那 ...

  6. html第九节课

    正则表达式和marquee 1.表单验证<form></form> (1).非空验证(去空格) (2).对比验证(跟一个值对比) (3).范围验证(根据一个范围进行判断) (4 ...

  7. 58.fetch phbase

    1.fetch phbase工作流程 The coordinating node identifies which documents need to be fetched and issues a ...

  8. 用python实现进度条功能

    我在做python的作业:ftp服务时,客户端能够上传.下载文件,这个时候需要编写一个进度条来表示当前的传输进度. 我们可以使用sys,模块来完成任务,需要用到sys.stdout这个方法: 程序示例 ...

  9. Git 基础教程 之 Git 安装 (windows)

    一,安装Git,访问下面网址进行下载 https://www.git-scm.com/download/ 或者 https://pan.baidu.com/s/19imFBVHA2Yibmw1dyza ...

  10. 【例题4-2 uva489】Hangman Judge

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 水题. 中间就赢了算赢.(重复说,算错 [代码] #include <bits/stdc++.h> using name ...