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);
|
}
|