前言:
此章节用到的知识点:mybatisPlus ;参考网址:https://www.bilibili.com/video/BV1Xu411A7tL?p=7&vd_source=79bbd5b76bfd74c2ef1501653cee29d6
正常新建一个接口:
再新建这个接口的实现类:
修改接口:
修改实现类:
然后就可以注入并使用了:
=============================================================
此章节还需要参考:创建一个类来统一结果返回:https://blog.csdn.net/qq_42331202/article/details/115823134
统一的返回结果是json格式,类似下面的数据结构
{ "success":布尔,//代表响应是否成功 "code":数字,//响应码 "message":字符串,//返回消息 "data":HashMap //返回数据 }
首先写一个接口,定义数据返回响应码
package com.example.learn.common; /** * @author : wangbo * @version : 1.0 * @date :Create in 2021/4/18 * @description : */ public interface ResultCode { // 成工时返回的状态码 public static Integer SUCCESS=20000; // 失败是返回的状态码 public static Integer ERROR=20001; }
写统一返回结果的类
package com.example.learn.common; import lombok.Data; import java.util.HashMap; import java.util.Map; /** * @author : wangbo * @version : 1.0 * @date :Create in 2021/4/18 * @description : */ @Data public class Result { private boolean success; private Integer code; private String message; private Map<String,Object> data=new HashMap<>(); private Result(){ } public static Result ok(){ Result result=new Result(); result.setSuccess(true); result.setCode(ResultCode.SUCCESS); result.setMessage("成功"); return result; } public static Result error(){ Result result=new Result(); result.setSuccess(false); result.setCode(ResultCode.ERROR); result.setMessage("失败"); return result; } public Result success(boolean success){ this.setSuccess(success); return this; } public Result code(Integer code){ this.setCode(code); return this; } public Result message(String message) { this.setMessage(message); return this; } public Result data(Map<String, Object> data) { this.setData(data); return this; } }
======================================================================
1
1
1
标签:code,java,success,redis,Result,return,随笔,public,result From: https://www.cnblogs.com/xiaobaibailongma/p/17744589.html