From 3be168b3b2ad068a28f44c28238f542e5b08eeda Mon Sep 17 00:00:00 2001 From: pho6e2qjw <1563847437@qq.com> Date: Wed, 26 Jun 2024 08:39:32 +0800 Subject: [PATCH] Add ResultGenerator.java --- ResultGenerator.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ResultGenerator.java diff --git a/ResultGenerator.java b/ResultGenerator.java new file mode 100644 index 0000000..907a5a3 --- /dev/null +++ b/ResultGenerator.java @@ -0,0 +1,42 @@ +package com.power.travel.core; + +/** + * 响应结果生成工具 + */ +public class ResultGenerator { + + private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS"; + + + public static Result genSuccessResult() { + return new Result() + .setCode(ResultCode.SUCCESS) + .setMessage(DEFAULT_SUCCESS_MESSAGE); + } + + public static Result genSuccessResult(Object data) { + return new Result() + .setCode(ResultCode.SUCCESS) + .setMessage(DEFAULT_SUCCESS_MESSAGE) + .setData(data); + } + + public static Result genSuccessMsgResult(String msg) { + return new Result() + .setCode(ResultCode.SUCCESS) + .setMessage(msg); + } + + public static Result genFailResult(String message) { + return new Result() + .setCode(ResultCode.FAIL) + .setMessage(message); + } + + public static Result genResult(String message) { + return new Result() + .setCode(ResultCode.DATA_ERROR) + .setMessage(message); + } + +}