53 lines
1.9 KiB
Java
53 lines
1.9 KiB
Java
|
|
package com.zhangmeng.online.exam.controller;
|
||
|
|
|
||
|
|
import com.zhangmeng.online.exam.dao.QuestionOptionDao;
|
||
|
|
import com.zhangmeng.online.exam.dto.Result;
|
||
|
|
import com.zhangmeng.online.exam.entity.QuestionOption;
|
||
|
|
import com.zhangmeng.online.exam.entity.User;
|
||
|
|
import com.zhangmeng.online.exam.utils.PageUtils;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.data.domain.Page;
|
||
|
|
import org.springframework.data.domain.PageRequest;
|
||
|
|
import org.springframework.data.domain.Pageable;
|
||
|
|
import org.springframework.data.domain.Sort;
|
||
|
|
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/18 11:38
|
||
|
|
* @version: 1.0
|
||
|
|
*/
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/option")
|
||
|
|
public class QuestionOptionController {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private QuestionOptionDao questionOptionDao;
|
||
|
|
|
||
|
|
@RequestMapping("/list")
|
||
|
|
public Result list(Integer pageNum, Integer pageSize) {
|
||
|
|
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize);
|
||
|
|
Page<QuestionOption> all = questionOptionDao.findAll(pageable);
|
||
|
|
List<QuestionOption> list = all.getContent();
|
||
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
||
|
|
for (QuestionOption option : list) {
|
||
|
|
Map<String, Object> map = new HashMap<>();
|
||
|
|
map.put("id", option.getId());
|
||
|
|
map.put("name", option.getOptionName());
|
||
|
|
map.put("optionContent", option.getOptionContent());
|
||
|
|
map.put("isAnswer", option.getIsAnswer());
|
||
|
|
map.put("addTime", option.getAddTime());
|
||
|
|
map.put("explanation",option.getExplanation());
|
||
|
|
resultList.add(map);
|
||
|
|
}
|
||
|
|
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|