修改返回结果为泛型方式

This commit is contained in:
2025-07-12 20:28:49 +08:00
parent 725c7dcea2
commit 59b4a5e8cf
26 changed files with 652 additions and 294 deletions

View File

@ -10,18 +10,25 @@ import com.ruoyi.common.utils.StringUtils;
*
* @author ruoyi
*/
public class AjaxResult extends HashMap<String, Object>
public class AjaxResult<T>
{
private static final long serialVersionUID = 1L;
private int code;
private String msg;
private T data;
// private String roleGroup;
// private String postGroup;
// private String imgUrl;
/** 状态码 */
public static final String CODE_TAG = "code";
/** 返回内容 */
public static final String MSG_TAG = "msg";
/** 数据对象 */
public static final String DATA_TAG = "data";
// /** 状态码 */
// public static final String CODE_TAG = "code";
//
// /** 返回内容 */
// public static final String MSG_TAG = "msg";
//
// /** 数据对象 */
// public static final String DATA_TAG = "data";
/**
* 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
@ -38,8 +45,8 @@ public class AjaxResult extends HashMap<String, Object>
*/
public AjaxResult(int code, String msg)
{
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
this.code = code;
this.msg = msg;
}
/**
@ -49,14 +56,11 @@ public class AjaxResult extends HashMap<String, Object>
* @param msg 返回内容
* @param data 数据对象
*/
public AjaxResult(int code, String msg, Object data)
public AjaxResult(int code, String msg, T data)
{
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
if (StringUtils.isNotNull(data))
{
super.put(DATA_TAG, data);
}
this.code = code;
this.msg = msg;
this.data = data;
}
/**
@ -64,7 +68,7 @@ public class AjaxResult extends HashMap<String, Object>
*
* @return 成功消息
*/
public static AjaxResult success()
public static <T> AjaxResult<T> success()
{
return AjaxResult.success("操作成功");
}
@ -74,7 +78,7 @@ public class AjaxResult extends HashMap<String, Object>
*
* @return 成功消息
*/
public static AjaxResult success(Object data)
public static <T> AjaxResult<T> success(T data)
{
return AjaxResult.success("操作成功", data);
}
@ -85,7 +89,7 @@ public class AjaxResult extends HashMap<String, Object>
* @param msg 返回内容
* @return 成功消息
*/
public static AjaxResult success(String msg)
public static <T> AjaxResult<T> success(String msg)
{
return AjaxResult.success(msg, null);
}
@ -97,9 +101,9 @@ public class AjaxResult extends HashMap<String, Object>
* @param data 数据对象
* @return 成功消息
*/
public static AjaxResult success(String msg, Object data)
public static <T> AjaxResult<T> success(String msg, T data)
{
return new AjaxResult(HttpStatus.SUCCESS, msg, data);
return new AjaxResult<T>(HttpStatus.SUCCESS, msg, data);
}
/**
@ -108,7 +112,7 @@ public class AjaxResult extends HashMap<String, Object>
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult warn(String msg)
public static <T> AjaxResult<T> warn(String msg)
{
return AjaxResult.warn(msg, null);
}
@ -120,9 +124,9 @@ public class AjaxResult extends HashMap<String, Object>
* @param data 数据对象
* @return 警告消息
*/
public static AjaxResult warn(String msg, Object data)
public static <T> AjaxResult<T> warn(String msg, T data)
{
return new AjaxResult(HttpStatus.WARN, msg, data);
return new AjaxResult<T>(HttpStatus.WARN, msg, data);
}
/**
@ -130,7 +134,7 @@ public class AjaxResult extends HashMap<String, Object>
*
* @return 错误消息
*/
public static AjaxResult error()
public static <T> AjaxResult<T> error()
{
return AjaxResult.error("操作失败");
}
@ -141,7 +145,7 @@ public class AjaxResult extends HashMap<String, Object>
* @param msg 返回内容
* @return 错误消息
*/
public static AjaxResult error(String msg)
public static <T> AjaxResult<T> error(String msg)
{
return AjaxResult.error(msg, null);
}
@ -153,7 +157,7 @@ public class AjaxResult extends HashMap<String, Object>
* @param data 数据对象
* @return 错误消息
*/
public static AjaxResult error(String msg, Object data)
public static <T> AjaxResult<T> error(String msg, Object data)
{
return new AjaxResult(HttpStatus.ERROR, msg, data);
}
@ -177,7 +181,7 @@ public class AjaxResult extends HashMap<String, Object>
*/
public boolean isSuccess()
{
return Objects.equals(HttpStatus.SUCCESS, this.get(CODE_TAG));
return this.code == HttpStatus.SUCCESS;
}
/**
@ -187,7 +191,7 @@ public class AjaxResult extends HashMap<String, Object>
*/
public boolean isWarn()
{
return Objects.equals(HttpStatus.WARN, this.get(CODE_TAG));
return this.code == HttpStatus.WARN;
}
/**
@ -197,7 +201,31 @@ public class AjaxResult extends HashMap<String, Object>
*/
public boolean isError()
{
return Objects.equals(HttpStatus.ERROR, this.get(CODE_TAG));
return this.code == HttpStatus.ERROR;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
/**
@ -207,10 +235,10 @@ public class AjaxResult extends HashMap<String, Object>
* @param value 值
* @return 数据对象
*/
@Override
public AjaxResult put(String key, Object value)
{
super.put(key, value);
return this;
}
// @Override
// public AjaxResult put(String key, Object value)
// {
// super.put(key, value);
// return this;
// }
}

View File

@ -0,0 +1,29 @@
package com.ruoyi.common.core.domain.model;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import java.io.Serializable;
import java.util.List;
public class AuthRole implements Serializable {
private static final long serialVersionUID = 1L;
private List<SysRole> roles;
private SysUser user;
public List<SysRole> getRoles() {
return roles;
}
public void setRoles(List<SysRole> roles) {
this.roles = roles;
}
public SysUser getUser() {
return user;
}
public void setUser(SysUser user) {
this.user = user;
}
}

View File

@ -0,0 +1,40 @@
package com.ruoyi.common.core.domain.model;
import java.io.Serializable;
/**
* 返回的验证码数据
*/
public class Captcha implements Serializable {
private static final long serialVersionUID = 1L;
private String img;
private Boolean captchaEnabled;
private String uuid;
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public Boolean getCaptchaEnabled() {
return captchaEnabled;
}
public void setCaptchaEnabled(Boolean captchaEnabled) {
this.captchaEnabled = captchaEnabled;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -0,0 +1,28 @@
package com.ruoyi.common.core.domain.model;
import com.ruoyi.common.core.domain.TreeSelect;
import java.io.Serializable;
import java.util.List;
public class DeptTree implements Serializable {
private static final long serialVersionUID = 1L;
private List<Long> checkedKeys;
private List<TreeSelect> depts;
public List<Long> getCheckedKeys() {
return checkedKeys;
}
public void setCheckedKeys(List<Long> checkedKeys) {
this.checkedKeys = checkedKeys;
}
public List<TreeSelect> getDepts() {
return depts;
}
public void setDepts(List<TreeSelect> depts) {
this.depts = depts;
}
}

View File

@ -0,0 +1,60 @@
package com.ruoyi.common.core.domain.model;
import com.ruoyi.common.core.domain.entity.SysUser;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
public class Info implements Serializable {
private static final long serialVersionUID = 1L;
private Set<String> permissions;
private Set<String> roles;
private SysUser user;
private boolean isDefaultModifyPwd;
private boolean isPasswordExpired;
private List<Long> postIds;
private String roleIds;
public Set<String> getPermissions() {
return permissions;
}
public void setPermissions(Set<String> permissions) {
this.permissions = permissions;
}
public Set<String> getRoles() {
return roles;
}
public void setRoles(Set<String> roles) {
this.roles = roles;
}
public SysUser getUser() {
return user;
}
public void setUser(SysUser user) {
this.user = user;
}
public boolean getIsDefaultModifyPwd() {
return isDefaultModifyPwd;
}
public void setIsDefaultModifyPwd(boolean isDefaultModifyPwd) {
this.isDefaultModifyPwd = isDefaultModifyPwd;
}
public boolean getIsPasswordExpired() {
return isPasswordExpired;
}
public void setIsPasswordExpired(boolean isPasswordExpired) {
this.isPasswordExpired = isPasswordExpired;
}
}

View File

@ -0,0 +1,57 @@
package com.ruoyi.common.core.domain.model;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import java.io.Serializable;
import java.util.List;
public class Infos implements Serializable {
private static final long serialVersionUID = 1L;
private SysUser user;
private List<Long> postIds;
private List<Long> roleIds;
private List<SysRole> roles;
private List<SysPost> posts;
public SysUser getUser() {
return user;
}
public void setUser(SysUser user) {
this.user = user;
}
public List<Long> getPostIds() {
return postIds;
}
public void setPostIds(List<Long> postIds) {
this.postIds = postIds;
}
public List<Long> getRoleIds() {
return roleIds;
}
public void setRoleIds(List<Long> roleIds) {
this.roleIds = roleIds;
}
public List<SysRole> getRoles() {
return roles;
}
public void setRoles(List<SysRole> roles) {
this.roles = roles;
}
public List<SysPost> getPosts() {
return posts;
}
public void setPosts(List<SysPost> posts) {
this.posts = posts;
}
}

View File

@ -0,0 +1,29 @@
package com.ruoyi.common.core.domain.model;
import com.ruoyi.common.core.domain.TreeSelect;
import java.io.Serializable;
import java.util.List;
public class MenuTreeselect implements Serializable {
private static final long serialVersionUID = 1L;
private List<Long> checkedKeys;
private List<TreeSelect> menus;
public List<Long> getCheckedKeys() {
return checkedKeys;
}
public void setCheckedKeys(List<Long> checkedKeys) {
this.checkedKeys = checkedKeys;
}
public List<TreeSelect> getMenus() {
return menus;
}
public void setMenus(List<TreeSelect> menus) {
this.menus = menus;
}
}

View File

@ -0,0 +1,23 @@
package com.ruoyi.common.core.domain.model;
public class RoleGroup {
private static final long serialVersionUID = 1L;
private String roleGroup;
private String postGroup;
public String getRoleGroup() {
return roleGroup;
}
public void setRoleGroup(String roleGroup) {
this.roleGroup = roleGroup;
}
public String getPostGroup() {
return postGroup;
}
public void setPostGroup(String postGroup) {
this.postGroup = postGroup;
}
}

View File

@ -0,0 +1,124 @@
package com.ruoyi.common.core.domain.model;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 岗位表 sys_post
*
* @author ruoyi
*/
public class SysPost extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 岗位序号 */
@Excel(name = "岗位序号", cellType = ColumnType.NUMERIC)
private Long postId;
/** 岗位编码 */
@Excel(name = "岗位编码")
private String postCode;
/** 岗位名称 */
@Excel(name = "岗位名称")
private String postName;
/** 岗位排序 */
@Excel(name = "岗位排序")
private Integer postSort;
/** 状态0正常 1停用 */
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private String status;
/** 用户是否存在此岗位标识 默认不存在 */
private boolean flag = false;
public Long getPostId()
{
return postId;
}
public void setPostId(Long postId)
{
this.postId = postId;
}
@NotBlank(message = "岗位编码不能为空")
@Size(min = 0, max = 64, message = "岗位编码长度不能超过64个字符")
public String getPostCode()
{
return postCode;
}
public void setPostCode(String postCode)
{
this.postCode = postCode;
}
@NotBlank(message = "岗位名称不能为空")
@Size(min = 0, max = 50, message = "岗位名称长度不能超过50个字符")
public String getPostName()
{
return postName;
}
public void setPostName(String postName)
{
this.postName = postName;
}
@NotNull(message = "显示顺序不能为空")
public Integer getPostSort()
{
return postSort;
}
public void setPostSort(Integer postSort)
{
this.postSort = postSort;
}
public String getStatus()
{
return status;
}
public void setStatus(String status)
{
this.status = status;
}
public boolean isFlag()
{
return flag;
}
public void setFlag(boolean flag)
{
this.flag = flag;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("postId", getPostId())
.append("postCode", getPostCode())
.append("postName", getPostName())
.append("postSort", getPostSort())
.append("status", getStatus())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
}

View File

@ -0,0 +1,25 @@
package com.ruoyi.common.core.domain.model;
import com.ruoyi.common.core.domain.entity.SysUser;
public class SysUserExt extends SysUser {
private static final long serialVersionUID = 1L;
private String roleGroup;
private String postGroup;
public String getRoleGroup() {
return roleGroup;
}
public void setRoleGroup(String roleGroup) {
this.roleGroup = roleGroup;
}
public String getPostGroup() {
return postGroup;
}
public void setPostGroup(String postGroup) {
this.postGroup = postGroup;
}
}

View File

@ -0,0 +1,42 @@
package com.ruoyi.common.core.domain.model;
public class Upload {
private static final long serialVersionUID = 1L;
private String url;
private String fileName;
private String newFileName;
private String originalFilename;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getNewFileName() {
return newFileName;
}
public void setNewFileName(String newFileName) {
this.newFileName = newFileName;
}
public String getOriginalFilename() {
return originalFilename;
}
public void setOriginalFilename(String originalFilename) {
this.originalFilename = originalFilename;
}
}

View File

@ -8,7 +8,7 @@ import java.util.List;
*
* @author ruoyi
*/
public class TableDataInfo implements Serializable
public class TableDataInfo<T> implements Serializable
{
private static final long serialVersionUID = 1L;
@ -16,7 +16,7 @@ public class TableDataInfo implements Serializable
private long total;
/** 列表数据 */
private List<?> rows;
private List<T> rows;
/** 消息状态码 */
private int code;
@ -37,7 +37,7 @@ public class TableDataInfo implements Serializable
* @param list 列表数据
* @param total 总记录数
*/
public TableDataInfo(List<?> list, long total)
public TableDataInfo(List<T> list, long total)
{
this.rows = list;
this.total = total;
@ -58,7 +58,7 @@ public class TableDataInfo implements Serializable
return rows;
}
public void setRows(List<?> rows)
public void setRows(List<T> rows)
{
this.rows = rows;
}