一、在JDL的application配置中添加feature:dataScope
application {
  config {
    applicationType monolith
    title "瀚海工作平台"
    footer ""
    baseName LimsMonolith
    packageName com.eyun
    appVersion "0.0.1"
    serverPort 8891
    authenticationType jwt
    cacheProvider no
    databaseType sql
    devDatabaseType mysql
    prodDatabaseType mysql
    searchEngine false
    serviceDiscoveryType false
    buildTool maven
    enableSwaggerCodegen true
    embeddableLaunchScript false
    clientPackageManager npm
    clientFramework angularX
    clientTheme none
    reactive false
    jhiPrefix jhi
    dtoSuffix DTO
    otherModules []
    websocket spring-websocket
    enableTranslation true
    languages [zh-cn,en]
    nativeLanguage zh-cn
    devDatabasePassword "zgp30RKxVmurmnGe"
    devDatabaseUrl "www.eyun.online:3306"
    prodDatabasePassword "YVrcuPQihPLk7Mpv"
    prodDatabaseUrl "192.168.8.100:3306"
    testFrameworks []
    licenseManager "license4j"
    features [superadmin,crypto,importPreview,dataScope,tenancy,oplog]
    jwtSecretKey "TGltc01vbm9saXRoMjAyMuWunumqjOS/oeaBr+euoeeQhuezu+e7n2NvbS5leXVuODg5MUxpbXNNb25vbGl0aDIwMjLlrp7pqozkv6Hmga/nrqHnkIbns7vnu59jb20u"
  }
  entities *
} 
二、自定义Entity:User,并添加@role("USER")
/**
 * 用户
 */
@paginate(pagination)
@system
@ChangelogDate(20220808080808)
@role("USER")
entity User {
	@system
	email String
	@system
	lastName String
	@id
	@system
	login String maxlength(50)
}
relationship ManyToMany {
    User{@translate(zh-cn="部门")department(label,*)} to Department{@translate(zh-cn="职工")user(login,firstName)},
} 
三、在需要添加数据权限的Entity前添加注释@dataScope
/**
 * 职工
 */
@paginate(pagination)
@translate(zh-cn="职工")
@ChangelogDate(20220809080808)
@dataScope
entity Employee {
    @translate(zh-cn="姓名")
    name String required minlength(2),
    @translate(zh-cn="工号")
    @id empno String unique,
    @translate(zh-cn="手机号")
    @crypto(SM2="???*****???")
    mobile String unique minlength(2),
    @translate(zh-cn="身份证号码")
    @crypto(SM2="????*****????")
    idcard String required unique minlength(2),
    @translate(zh-cn="微信openid")
    @crypto(SM2="????*****????")
    openid String unique,
    @translate(zh-cn="微信昵称")
    nickname String,
    @translate(zh-cn="头像地址")
    avatarUrl String,
} 
四、在管理界面新建用户
系统在创建用户的时候会创建对应的用户唯一的权限,如用户test对应权限ROLE_USER_test。

五、在entity对应的编辑界面选择数据权限
数据x

五、在entity对应的列表界面查看数据
用户只能看到在步骤四中设置对应的权限的用户能看到其数据。














![2023年中国建筑安装行业市场现状分析:占比建筑业总产值8.4%[图]](https://img-blog.csdnimg.cn/img_convert/1f185911d1797ca1d4beca22e26a04e1.png)





