2025-03-07 10:19:30 +00:00
|
|
|
package com.zhangmeng.online.exam.controller;
|
|
|
|
|
|
|
|
|
|
import com.zhangmeng.online.exam.dao.PermissionDao;
|
|
|
|
|
import com.zhangmeng.online.exam.dto.Result;
|
|
|
|
|
import com.zhangmeng.online.exam.entity.Permission;
|
|
|
|
|
import com.zhangmeng.online.exam.entity.Role;
|
2025-03-14 08:54:45 +00:00
|
|
|
import com.zhangmeng.online.exam.utils.PageUtils;
|
2025-03-07 10:19:30 +00:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2025-03-14 08:54:45 +00:00
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.data.domain.Sort;
|
2025-03-07 10:19:30 +00:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author zm
|
|
|
|
|
* @date 2025/3/7 9:46
|
|
|
|
|
* @version: 1.0
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/permission")
|
|
|
|
|
public class PermissionController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PermissionDao permissionDao;
|
|
|
|
|
|
2025-03-14 08:54:45 +00:00
|
|
|
/**
|
|
|
|
|
* // 基本分页(无排序)
|
|
|
|
|
* Pageable pageable = PageRequest.of(0, 10);
|
|
|
|
|
*
|
|
|
|
|
* // 分页+排序(单字段)
|
|
|
|
|
* Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "createTime");
|
|
|
|
|
*
|
|
|
|
|
* // 分页+多字段排序
|
|
|
|
|
* Sort sort = Sort.by(Sort.Order.asc("age"), Sort.Order.desc("name"));
|
|
|
|
|
* Pageable pageable = PageRequest.of(0, 10, sort);
|
|
|
|
|
* @param pageNum
|
|
|
|
|
* @param pageSize
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2025-03-07 10:19:30 +00:00
|
|
|
@RequestMapping("/list")
|
2025-03-14 08:54:45 +00:00
|
|
|
public Result list(Integer pageNum, Integer pageSize) {
|
|
|
|
|
|
|
|
|
|
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize, Sort.Direction.DESC, "addTime");
|
|
|
|
|
Page<Permission> all = permissionDao.findAll(pageable);
|
|
|
|
|
List<Permission> list = all.getContent();
|
2025-03-07 10:19:30 +00:00
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
for (Permission permission : list) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("id", permission.getId());
|
|
|
|
|
map.put("name", permission.getName());
|
|
|
|
|
map.put("desc", permission.getDescription());
|
|
|
|
|
map.put("url", permission.getUrl());
|
|
|
|
|
resultList.add(map);
|
|
|
|
|
}
|
2025-03-14 08:54:45 +00:00
|
|
|
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
2025-03-07 10:19:30 +00:00
|
|
|
}
|
|
|
|
|
}
|