DoydoQuery v2
首页GitHub
简体中文
简体中文
  • 项目介绍
  • 快速上手
  • 基础用法
    • 增删查改接口
    • 中间表访问接口
    • 数据库方言
    • 分表增删查改
    • 打印SQL日志
  • 实体对象映射
    • 实体对象
    • 关联实体
  • 查询对象映射
    • 查询对象构建
    • 谓词后缀字段
    • 逻辑后缀字段
    • 子查询字段
    • ER关系字段
    • 自定义字段
    • 分页对象
  • 聚合查询
    • 视图对象
    • Having对象
    • 外连接
  • 相关资源
    • 文章
      • 从ORM到OQM:一种基于对象的SQL语句构造方案
由 GitBook 提供支持
在本页
  • 表结构
  • 定义
  • 使用
  • 访问

这有帮助吗?

  1. 基础用法

中间表访问接口

表结构

create table t_user_and_role (user_id bigint, role_id int);

定义

@Bean
public AssociativeService<Long, Integer> userAndRoleAssociativeService() {
    return new TemplateAssociativeService<>("t_user_and_role", "userId", "roleId");
}

使用

@RestController
class AuthController {
    @Resource
    AssociativeService<Long, Integer> userAndRoleAssociativeService;

    @GetPostMapping("reallocateRolesForUser")
    public void reallocateRoles(Long userId, @RequestParam List<Integer> roleIds) {
        userAndRoleAssociativeService.reallocateForLeft(userId, roleIds);
    }
}

访问

访问该接口将执行以下 SQL语句

DELETE FROM t_user_and_role WHERE userId = ?;
INSERT INTO t_user_and_role (userId, roleId) values (?, ?)[, (?, ?)];
上一页增删查改接口下一页数据库方言

最后更新于2个月前

这有帮助吗?