mybatis一对多的mapper写法

package com.stu.manage.demo.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.security.core.authority.SimpleGrantedAuthority;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@TableName(value = "tb_user", resultMap = "BaseResultMap")
@AllArgsConstructor
@NoArgsConstructor
public class TbUser {

    /**
     * 配置主键生成策略
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField("username")
    @NotNull
    private String userName;

    @TableField("password")
    @NotNull
    private String passWord;

    @NotNull
    private String phone;

    private String email;

    @TableField(value = "created", fill = FieldFill.INSERT)
    @NotNull
    private Date createTime;

    @TableField(value = "updated", fill = FieldFill.INSERT_UPDATE)
    @NotNull
    private Date modifyTime;

    /**
     * 用户表和用户权限中间表是一对多的关系
     */
    private List userRoles;

    public List getRoles() {
        return null;
    }
}

package com.stu.manage.demo.entity;

import java.util.Date;

import javax.validation.constraints.NotNull;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class TbUserRole {

    /**
     * 配置主键生成策略
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField("user_id")
    @NotNull
    private Long userId;

    @TableField("role_id")
    @NotNull
    private Long roleId;
}

package com.stu.manage.demo.mapper;

import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.stu.manage.demo.entity.TbRole;
import com.stu.manage.demo.entity.TbUser;

@Repository
public interface TbUserMapper extends BaseMapper {

    Integer findCount();
}




  
    
    
    
    
    
    
    
    
  

  
  
    
    id, username, `password`, phone, email, created, updated
  

  

你可能感兴趣的:(java,mysql,数据库,database)