lrj
4 天以前 4fa9591629721797386fc11836e3a9deb69cd58c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.rongyichuang.role.repository;
 
import com.rongyichuang.role.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
 
import java.util.List;
import java.util.Optional;
 
@Repository
public interface RoleRepository extends JpaRepository<Role, Long> {
    
    /**
     * 根据角色代码查找角色
     */
    Optional<Role> findByCode(String code);
    
    /**
     * 查找所有启用状态的角色
     */
    @Query("SELECT r FROM Role r WHERE r.state = 1 ORDER BY r.id")
    List<Role> findAllActiveRoles();
    
    /**
     * 根据状态查找角色
     */
    List<Role> findByStateOrderById(Integer state);
    
    /**
     * 根据角色名称模糊查询
     */
    @Query("SELECT r FROM Role r WHERE r.name LIKE %:name% ORDER BY r.id")
    List<Role> findByNameContaining(String name);
}