1.添加自定义返回值R \n2.测试自定义返回值

This commit is contained in:
haotianmingyue 2025-06-27 10:14:07 +08:00
parent c9fda9f5b1
commit 25b785883a
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,54 @@
package com.example.testspring.demos.modules.common.utils;
import java.util.HashMap;
import java.util.Map;
public class R extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
public R() {
put("code", 0);
put("msg", "success");
}
public static R error() {
return error(500, "未知异常,请联系管理员");
}
public static R error(String msg) {
return error(500, msg);
}
public static R error(int code, String msg) {
R r = new R();
r.put("code", code);
r.put("msg", msg);
return r;
}
public static R ok(String msg) {
R r = new R();
r.put("msg", msg);
return r;
}
public static R ok(Map<String, Object> map) {
R r = new R();
r.putAll(map);
return r;
}
public static R ok() {
return new R();
}
public R put(String key, Object value) {
super.put(key, value);
return this;
}
}

View File

@ -1,6 +1,7 @@
package com.example.testspring.demos.modules.user.controller;
import com.example.testspring.demos.modules.common.utils.R;
import com.example.testspring.demos.modules.user.entity.Robot;
import com.example.testspring.demos.modules.user.entity.SysMenu;
import com.example.testspring.demos.modules.user.entity.SysUser;
@ -32,4 +33,9 @@ public class testController {
public List<Robot> test(){
return robotService.selectRobotList(new Robot());
}
@GetMapping("/testR")
public R testR(){
return R.ok().put("data",robotService.selectRobotList(new Robot()));
}
}

View File

@ -12,4 +12,5 @@ server:
mybatis:
# mapper????
mapper-locations: classpath:mapper/**/*.xml