public class BasicUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected static org.slf4j.Logger |
LOG |
| 构造器和说明 |
|---|
BasicUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Map<String,Object> |
assemblyRequestMap()
将请求的request的参数重新组装。
|
static String |
assemblyRequestUrlParams()
将请求的request的参数重新组装。
|
static String |
assemblyRequestUrlParams(String[] filter)
将请求的request的参数重新组装。
|
static com.github.pagehelper.PageInfo |
endPage(List list) |
static com.github.pagehelper.PageInfo |
endPage(List list,
String name) |
static Map |
enumToMap(net.mingsoft.base.constant.e.BaseEnum[] baseEnum)
枚举类型转map类型
|
static Map |
enumToMap(net.mingsoft.base.constant.e.BaseEnum[] baseEnum,
boolean idKey)
枚举类型转map类型
|
static <T> T |
filter(T obj,
String... filters)
过滤字段
此方法不推荐使用,推荐使用@@JsonIgnore 实体字段注解方式,
注意:hutool的工具会将时间变成时间戳,所以次方法默认将日期格式全部转换为 yyyy-MM-dd hh:mm:ss
|
static Field[] |
getAllFields(Object object)
获取对象所有字段 包括父类
|
static AppEntity |
getApp()
获取当前模块对应的app
必返回一条
注意:没有站群插件appUrl会设置当前域名
|
static Boolean |
getBoolean(String param)
获取布尔值
HttpServletRequest对象
|
static Boolean |
getBoolean(String param,
Boolean def)
获取布尔值
HttpServletRequest对象
|
static String |
getClassPath(String filePath)
获取spingboot 对应下的资源文件
|
static String |
getContextPath()
获取上下文路径
|
static String |
getCookie(net.mingsoft.base.constant.e.BaseCookieEnum key)
获取Cookie的值
|
static String |
getCookie(String key)
获取Cookie的值
|
static String |
getDomain()
获取请求域名,域名不包括http请求协议头
|
static int[] |
getIds() |
static Integer |
getInt(String param) |
static Integer |
getInt(String param,
int def)
获取整型值
HttpServletRequest对象
|
static int[] |
getInts(String param)
获取整型值数组
|
static int[] |
getInts(String param,
String split)
获取整型值数组
|
static String |
getIp()
获取请求客户端ip
|
String |
getMACAddress(String ip)
获取对应ip地址的mac地址
|
static ManagerEntity |
getManager()
获取当前登陆管理员信息(替代session方式获取)
|
static String |
getMimeType(InputStream fileInput,
String fileName)
获取文件真实类型
|
static int |
getPageNo()
当前页码
|
static int |
getPageSize()
每页显示数量
|
static String |
getRealPath(String filePath)
获取filePath的物理路径
文件分隔符应该使用 File.separator 或 / 避免在linux下无法识别路径
|
static String |
getRealTemplatePath(String filePath)
获取filePath的物理路径
|
static String |
getRequestUrl(javax.servlet.http.HttpServletRequest request)
获取当前请求地址,包括参数会才有?
|
static Object |
getSession(net.mingsoft.base.constant.e.BaseSessionEnum key)
获取session的值
HttpServletRequest对象
|
static Object |
getSession(String key)
获取session的值
HttpServletRequest对象
|
static String |
getString(String param)
获取字符串值
HttpServletRequest对象
|
static String |
getString(String param,
String def)
获取字符串值
HttpServletRequest对象
|
static String |
getUrl()
获取项目路径
|
static String |
getUrl(String server)
获取项目路径
|
static AppEntity |
getWebsiteApp()
获取当前模块对应的app
使用了站群插件才会有值
|
static boolean |
isAjaxRequest(javax.servlet.http.HttpServletRequest request)
判断是否为ajax XMLHttpRequest
|
static boolean |
isMobileDevice()
根据当前请求的特征,判断该请求是否来自手机终端,主要检测特殊的头信息,以及user-Agent这个header
|
static boolean |
isWechatBrowser()
判断是否是微信内置浏览器
如果用来判断是否为手机端的微信内置浏览器需和isMobileDevice()方法一起使用 |
static void |
orderBy(String orderBy,
String order)
列表排序
|
static void |
outString(javax.servlet.http.HttpServletResponse response,
String dataStr)
输出json数据,已弃用
请使用springmvc的@ResponseBody返回
ResultData包装对象 |
static void |
removeSession(net.mingsoft.base.constant.e.BaseSessionEnum key)
移除session的值
HttpServletRequest对象
|
static void |
removeSession(String key)
移除session的值
HttpServletRequest对象
|
static void |
removeUrlParams(String[] fitlers)
移除url参数
|
static Map |
resToMap(ResourceBundle rb)
资源文件转map类型
|
static Map |
resToMap(String resPath)
资源文件转map类型
|
static void |
setCookie(javax.servlet.http.HttpServletResponse response,
net.mingsoft.base.constant.e.BaseCookieEnum key,
Object value)
设置Cookie值,浏览器关闭cookie会被删除
|
static void |
setCookie(javax.servlet.http.HttpServletResponse response,
net.mingsoft.base.constant.e.BaseCookieEnum key,
Object value,
int expiry)
设置Cookie值
|
static void |
setCookie(javax.servlet.http.HttpServletResponse response,
String key,
String value,
int expiry)
设置Cookie值
|
static void |
setCookie(javax.servlet.http.HttpServletResponse response,
String domain,
String key,
String value,
int expiry)
设置Cookie值
|
static void |
setCookie(javax.servlet.http.HttpServletResponse response,
String domain,
String path,
String key,
String value,
int expiry)
设置cooke
|
static void |
setSession(net.mingsoft.base.constant.e.BaseSessionEnum key,
Object value)
设置session的值
HttpServletRequest对象
|
static void |
setSession(String key,
Object value)
设置session的值
HttpServletRequest对象
|
static void |
setValue(Object target,
String fieldName,
Object value)
通过反射给对象的指定字段赋值
|
static void |
startPage()
分页开始方法,必须配合BasicUtil.endPage()一起使用
此方法必须紧跟需要分页的查询语句,不能穿插其他sql否则会消耗掉分页次数导致异常。 |
static void |
startPage(boolean count)
分页开始方法,必须配合BasicUtil.endPage()一起使用
|
static void |
startPage(int pageNo,
int pageSize,
boolean count)
分页开始方法,必须配合BasicUtil.endPage()一起使用
|
public static AppEntity getApp()
public static AppEntity getWebsiteApp()
public static String getContextPath()
public static String getUrl(String server)
server - 指定servier主机public static String getUrl()
public static String getIp()
public static String getDomain()
public static void startPage()
public static int getPageSize()
public static int getPageNo()
public static void startPage(boolean count)
count - 是否统计总数 如果不需要分页使用falsepublic static void startPage(int pageNo,
int pageSize,
boolean count)
count - 是否统计总数 如果不需要分页使用falsepageNo - 当前页码pageSize - 一页显示数量public static void orderBy(String orderBy, String order)
orderBy - 排序字段,多个之间用,隔开order - 默认DESCpublic static com.github.pagehelper.PageInfo endPage(List list)
public static Boolean getBoolean(String param)
param - 参数名称public static Boolean getBoolean(String param, Boolean def)
param - 参数名称def - 默认值,如果参数不存在或不符合规则就用默认值替代public static Integer getInt(String param, int def)
param - 参数名称def - 默认值,如果参数不存在或不符合规则就用默认值替代public static String getString(String param, String def)
param - 参数名称def - 默认值,如果参数不存在或不符合规则就用默认值替代public static String getString(String param)
param - 参数名称public static int[] getInts(String param)
param - 参数名称public static int[] getInts(String param, String split)
param - 参数名称,如果param参数的值本身就是数组,将会忽略split参数split - 分割符号public static int[] getIds()
public static Map<String,Object> assemblyRequestMap()
public static String assemblyRequestUrlParams()
public static String assemblyRequestUrlParams(String[] filter)
filter - 需要过滤的字段public static void removeUrlParams(String[] fitlers)
fitlers - 需要移除的字段名称public static Object getSession(net.mingsoft.base.constant.e.BaseSessionEnum key)
key - 枚举类中的值public static Object getSession(String key)
key - 枚举类中的值public static void setSession(net.mingsoft.base.constant.e.BaseSessionEnum key,
Object value)
key - 枚举类中的值public static void setSession(String key, Object value)
key - 枚举类中的值public static void removeSession(net.mingsoft.base.constant.e.BaseSessionEnum key)
key - 枚举类中的值public static void removeSession(String key)
key - 枚举类中的值public static String getRealPath(String filePath)
filePath - 文件public static String getRealTemplatePath(String filePath)
filePath - 文件public static String getClassPath(String filePath)
filePath - public static void setValue(Object target, String fieldName, Object value)
target - 目标对象fieldName - 字段的名称value - 值public static Map enumToMap(net.mingsoft.base.constant.e.BaseEnum[] baseEnum)
baseEnum - 枚举类class.getEnumConstants()public static Map enumToMap(net.mingsoft.base.constant.e.BaseEnum[] baseEnum, boolean idKey)
baseEnum - 枚举类class.getEnumConstants()idKey - true的id为主键,false的name为主键public static Map resToMap(ResourceBundle rb)
rb - 资源文件public static String getCookie(net.mingsoft.base.constant.e.BaseCookieEnum key)
key - 枚举类中的值public static void setCookie(javax.servlet.http.HttpServletResponse response,
net.mingsoft.base.constant.e.BaseCookieEnum key,
Object value)
response - HttpServletResponse对象key - 枚举类中的值value - 存储对象public static ManagerEntity getManager()
public static void setCookie(javax.servlet.http.HttpServletResponse response,
net.mingsoft.base.constant.e.BaseCookieEnum key,
Object value,
int expiry)
response - HttpServletResponse对象key - 枚举类中的值value - 存储对象expiry - 过期时间,单位秒public static void setCookie(javax.servlet.http.HttpServletResponse response,
String key,
String value,
int expiry)
response - HttpServletResponse对象key - 枚举类中的值value - 存储对象expiry - 过期时间,单位秒public static void setCookie(javax.servlet.http.HttpServletResponse response,
String domain,
String key,
String value,
int expiry)
response - HttpServletResponse对象domain - 域key - 枚举类中的值value - 存储对象expiry - 过期时间,单位秒public static void setCookie(javax.servlet.http.HttpServletResponse response,
String domain,
String path,
String key,
String value,
int expiry)
response - domain - 域 如:baidu.com 没有www,没有端口path - 路径key - 名称value - 值expiry - 过期时间,单位秒 默认0,关闭窗口后该Cookie即失效 0删除cookiepublic static boolean isMobileDevice()
public static boolean isWechatBrowser()
public static boolean isAjaxRequest(javax.servlet.http.HttpServletRequest request)
request - public static <T> T filter(T obj,
String... filters)
obj - 过滤对象filters - 过滤参数public static void outString(javax.servlet.http.HttpServletResponse response,
String dataStr)
ResultData包装对象response - HttpServletResponse对象dataStr - 字符串public static String getMimeType(InputStream fileInput, String fileName)
fileInput - 文件流fileName - 文件名public static String getRequestUrl(javax.servlet.http.HttpServletRequest request)
request - 对象Copyright © 2024. All rights reserved.