mybits 操作指南
第一、一对一:
<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 操作指南的更多相关文章
- 【项目管理】GitHub使用操作指南
GitHub使用操作指南 作者:白宁超 2016年10月5日18:51:03> 摘要:GitHub的是版本控制和协作代码托管平台,它可以让你和其他人的项目从任何地方合作.相对于CVS和SVN的联 ...
- Tourist.js – 简单灵活的操作指南和导航插件
Tourist.js 是一个基于 Backbone 和 jQuery 开发的轻量库,帮助你在应用程序创建简单易用的操作指南和导航功能.相比网站,它更适合用于复杂的,单页网站类型的应用程序.Touris ...
- HHKB MAC 配置指南 操作指南 快捷键
1. 设备: mac电脑一台.hhkb键盘一个 2. 初级配置 (1)调节hhkb的模式为Macintosh模式:011001 (打开键盘侧边的滑盖,按照这个顺序调正) (2)Mac电脑安装官方驱动 ...
- 比较详细Python正则表达式操作指南(re使用)
比较详细Python正则表达式操作指南(re使用) Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式.Python 1.5之前版本则是通过 regex 模块提供 E ...
- WEBUS2.0 In Action - 索引操作指南(2)
上一篇:WEBUS2.0 In Action - 索引操作指南(1) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(1) 3. 添加.删除.撤销删除和修改文档 在WEBUS中要将 ...
- WEBUS2.0 In Action - 搜索操作指南 - (1)
上一篇:WEBUS2.0 In Action - 索引操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(2) 1. IQueriable中内置的搜索功能 在Webus ...
- WEBUS2.0 In Action - 搜索操作指南 - (2)
上一篇:WEBUS2.0 In Action - 搜索操作指南(1) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(3) 2. 使用Query Query是所有查询的基类, 它一 ...
- WEBUS2.0 In Action - 搜索操作指南 - (3)
上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...
- WEBUS2.0 In Action - 搜索操作指南 - (4)
上一篇:WEBUS2.0 In Action - 搜索操作指南(3) 6. 搜索多个索引 为了提升性能, 我们可以从多个索引同时进行搜索, Webus.Search.MultiSearcher提供了相 ...
随机推荐
- mac下配置nginx
nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,下面我们来了解下nginx的用法. 安装nginx 使用brew安装nginx brew install ...
- Retrofit 传递json 和 复杂参数类型List<T>
1 首先你要定义一个接口 @POST Call<String> post(@Url String url, @Body String info); 2 创建一个service public ...
- Android使用charles抓包
1.下载并安状软件,官网在此: 2.前题条件,电脑和手机必须在同一网段 3.在Charles界面选择菜单 proxy->proxy settings 勾选"Enable transpa ...
- ajax 三级联动写法
主页面代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 图片懒加载插件echo.js——改造
今天做一个列表项需要用到懒加载,搜到网友推荐的echo.js,试用了一下,还不错.除了懒加载,还提供了throttle——节流,即用户快速滑动列表时,很快滑过的项的图片不会加载,只会加载最后停下来的位 ...
- css+js+html实现的遮罩
——————页面遮罩(CSS+JS+HTML)—————— HTML: <div id="mask" class="mask"></div&g ...
- Net.Json 常用例子
#JsonConvert 例子 内容主要都是官方的例子,加上一些中文注释而已. 主要方便自己查询,分享一份出来. 参考文档: https://www.newtonsoft.com/json/help/ ...
- Table边框使用总结 ,只显示你要显示的边框
表格的常用属性 基本属性有:width(宽度).height(高度).border(边框值).cellspacing(表格的内宽,即表格与tr之间的间隔). cellpadding(表格内元素的间隔, ...
- 迭代器与index遍历
迭代器用于链式组织的序列. index用于线性组织的序列.
- Python统计字符串中出现次数最多的人名
人名最多数统计题目摘自https://python123.io 描述编程模板中给出了一个字符串,其中包含了含有重复的人名,请直接输出出现最多的人名. ...