Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mp sql,实体类,controller,对于id这个属性各玩各的,使用姿势不对吗? #162

Open
faithererer opened this issue Jan 25, 2025 · 0 comments

Comments

@faithererer
Copy link

  • mysql:
CREATE TABLE `sys_permission` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `parent_id` bigint(20) DEFAULT NULL COMMENT '父级权限ID',
  `permission_name` varchar(64) NOT NULL COMMENT '权限名称',
  `permission_code` varchar(64) NOT NULL COMMENT '权限编码',
  `permission_type` tinyint(4) NOT NULL COMMENT '权限类型:1-菜单 2-按钮 3-接口',
  `path` varchar(255) DEFAULT NULL COMMENT '路由地址',
  `component` varchar(255) DEFAULT NULL COMMENT '前端组件',
  `icon` varchar(255) DEFAULT NULL COMMENT '图标',
  `sort` int(11) DEFAULT '0' COMMENT '排序',
  `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态:0-禁用 1-启用',
  `created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_permission_code` (`permission_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限表';
  • 实体类
@Data
@ApiModel("权限表")
public class Permission implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    /**
    * 主键ID
    */
    @ApiModelProperty("主键ID")
    private Long id; 

other code...
}
  • controller
    /**
    * 新增或编辑
    */
    @PostMapping("/save")
    public Object save(@RequestBody Permission permission){
        log.info("permission:"+JSON.toJSONString(permission));
// permission_id是哪个列,我了个无中生有 🤣
        Permission oldPermission = permissionMapper.selectOne(new QueryWrapper<Permission>().eq("permission_id",permission.getPermissionId())); 
        permission.setUpdateTime(new Date());
        if(oldPermission!=null){
            permissionMapper.updateById(permission);
        }else{
        if(permissionMapper.selectOne(new QueryWrapper<Permission>().eq("permission_name",permission.getPermissionName()))!=null){ 
            return ReturnT.error("保存失败,名字重复");
        }
        permission.setCreateTime(new Date());
        permissionMapper.insert(permission);
        }
        return CommonResult.success("保存成功");
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant