这是在controller编写的执行功能
//分页查询功能
@ApiOperation(value = "根据讲师进行分页查询")
@GetMapping("pageTeacher/{current}/{limit}")
public R pageTeacher(@ApiParam(name = "current", value = "当前页码", required = true) @PathVariable long current,
@ApiParam(name = "limit", value = "每条记录数", required = true) @PathVariable long limit) {
Page<EduTeacher> teacherPage = new Page<EduTeacher>(current, limit);
int i=1/0;//自己加的异常报错
eduTeacherService.page(teacherPage, null);
long total = teacherPage.getTotal();
List<EduTeacher> records = teacherPage.getRecords();
return R.ok().data("total", total).data("records", records);
}
这是自己编写的异常处理程序
package com.wgl.servicebase.exceptionhandler;
import com.wgl.commonutils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 万葛亮
* @Date 2020 06 13 16:16
*/
@ControllerAdvice
public class GlobalExceptionHandler {
@ResponseBody//返回数据
@ExceptionHandler(Exception.class)//
public R error(Exception e) {
e.printStackTrace();
return R.error().message("进行了全局异常处理.....");
}
}
在swagger中出现的类响应状态
这是在idea中出现的提示