- 浏览: 139603 次
- 性别:
- 来自: 深圳
最新评论
-
wzk2111:
代码 可用,楼主的思路可以参考
javascript加密java解密 -
Imini123:
[align=center][color=red][/colo ...
freemarker实现通用分页,首页静态化,通用select,通用文章显示 -
igting:
js对+,@符号的加密应该有问题,java解密不对。
javascript加密java解密 -
Seanman:
初学freemarker,源码不全,不知道怎么用
freemarker实现通用分页,首页静态化,通用select,通用文章显示 -
无敌洋葱头:
目前这个只能对0-9 A-Z a-z加密,而且js还有问题。c ...
javascript加密java解密
package com.xxx.appmodel.domain.result; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import org.apache.commons.lang3.text.StrBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.xxx.appmodel.constant.UnknownErrorCodeConstant; import com.xxx.appmodel.localmsg.LocalMsgManager; import com.alibaba.fastjson.JSON; @SuppressWarnings("unchecked") public class BaseResult implements Serializable { private static final long serialVersionUID = 1719385495455011753L; private transient static final Logger log = LoggerFactory.getLogger(BaseResult.class); private transient boolean loggedException = false; private transient boolean loggedWarn = false; public BaseResult() { loggedException = false; loggedWarn = false; } static { new LocalMsgManager().init(); } /** * 给终端用户的错误提示 */ private Map<String, String> errorList = new HashMap<String, String>(); /** * 给其他模块开发者的提示信息 */ private Collection<String> warnList = new HashSet<String>(); /** * 出错时的重要输入参数 */ private String inputParamWhereCatch; /** * 异常时的堆栈,可网络两端都log,加大异常的知晓机会 */ private String detailStack; /** * 为false则表示业务请求没通过或发生系统异常。 * 为true则表示肯定没发生系统异常,但业务请求的成功与否还看具体接口定义/javadoc说明,或更多的字段 * * @return */ public boolean isSuccess() { if (!loggedException && detailStack != null) { log.error("{inputParamWhereCatch:'" + inputParamWhereCatch + "'}\r\n" + detailStack); loggedException = true; } if (!loggedWarn && !warnList.isEmpty()) { log.warn("{warnList:'" + warnList.toString() + "'}"); loggedWarn = true; } boolean isEmpty = errorList.isEmpty(); if (!isEmpty) { for (Map.Entry<String, String> entry : errorList.entrySet()) { String msg = UnknownErrorCodeConstant.getMsg(entry.getKey()); if (msg != null) { entry.setValue(msg); } } } return isEmpty; } /** * 非测试调试状态下(线上)少用这个,线上可以不log业务主动发现的问题,如密码不对 * @return */ public boolean isSuccessAndLogError() { boolean success = isSuccess(); if(!success){ log.error("{errorList:'" + errorList.toString() + "'}"); } return success; } /** * 先判断isSuccess()才能用,多重错误时可转用getErrorList() * * @return */ public String getErrorMsg() { if (errorList.isEmpty()) {// toString()/toJson()/beanCopy等调用getter的next()会抛异常 return ""; } return errorList.values().iterator().next(); } /** * 不适合时,可转用getErrorList() * @param seperator * @param displayCount * @return */ public String getErrorMsg(String seperator, int displayCount) { int count = 0; StringBuilder sb = new StringBuilder(60); for (String msg : errorList.values()) { sb.append(msg).append(seperator); count++; if (count > displayCount) { sb.append("还有" + (errorList.size() - displayCount) + "个错误信息未显示" + seperator); break; } } sb.delete(sb.length() - seperator.length(), sb.length()); return sb.toString(); } /** * 消息本地化可看 章节“消息本地化” http://wiki.inzwc.com/wiki/index.php/xxxAppModel#.E6.B6.88.E6.81.AF.E6.9C.AC.E5.9C.B0.E5.8C.96 * @return */ public Map<String, String> getErrorList() { return errorList; } public void setErrorList(Map<String, String> errorList) { this.errorList = errorList; } @Deprecated public Map<String, String> toLocalErrorList(Map<String, String> localMsgMap) { for (Map.Entry<String, String> entry : errorList.entrySet()) { String localMsg = localMsgMap.get(entry.getKey()); if (localMsg != null) { entry.setValue(localMsg); } } return errorList; } /** * 先判断isSuccess()才能用。 * * @return */ public String getErrorCode() { if (errorList.isEmpty()) {// 但有时toString()是直接调用,遇到没东西,next()就抛异常了 return null; } return errorList.keySet().iterator().next(); } public String getDetailStack() { return detailStack; } public void setDetailStack(String detailStack) { this.detailStack = detailStack; } public String getInputParamWhereCatch() { return inputParamWhereCatch; } public void setInputParamWhereCatch(String inputParamWhereCatch) { this.inputParamWhereCatch = inputParamWhereCatch; } /** * 如果log出重要输入参数能有助事情的话,请选用带inputParamWhereCatch的方法 * * @param errorCode * @param errorMsg */ public <SubClass extends BaseResult> SubClass withError(String errorCode, String errorMsg) { errorList.put(errorCode, errorMsg); return (SubClass) this; } public <SubClass extends BaseResult> SubClass withError(String errorCode) { String msg = UnknownErrorCodeConstant.getMsg(errorCode); if (msg == null) { msg = "遇到错误[" + errorCode + "],请截屏后告知客服检查或自行重试"; } errorList.put(errorCode, msg); return (SubClass) this; } public <SubClass extends BaseResult> SubClass withError(String errorCode, String errorMsg, String inputParamWhereCatch) { errorList.put(errorCode, errorMsg); this.inputParamWhereCatch = inputParamWhereCatch; return (SubClass) this; } /** * 只会包含convert错误信息过去,所以命名toErrorResult() * * @param result * @return */ public <SubClass extends BaseResult> SubClass toErrorResult(SubClass result) { result.setErrorList(errorList); result.setWarnList(warnList); result.setInputParamWhereCatch(inputParamWhereCatch); result.setDetailStack(detailStack); return result; } public <SubClass extends BaseResult> SubClass withErrorAndLog(String inputParamWhereCatch, Throwable e) { return withErrorAndLog(UnknownErrorCodeConstant.exceptionCanRetry, UnknownErrorCodeConstant.getMsg(UnknownErrorCodeConstant.exceptionCanRetry), inputParamWhereCatch, e); } public <SubClass extends BaseResult> SubClass withErrorAndLog(String errorCode, String inputParamWhereCatch, Throwable e) { return withErrorAndLog(errorCode, UnknownErrorCodeConstant.getMsg(errorCode), inputParamWhereCatch, e); } public <SubClass extends BaseResult> SubClass withErrorAndLog(String errorCode, String errorMsg, String inputParamWhereCatch, Throwable e) { StrBuilder sb = new StrBuilder(512); sb.append("{errorCode:'").append(errorCode) .append("', errorMsg:'").append(errorMsg) .append("', inputParamWhereCatch:'").append(inputParamWhereCatch).append("'}"); log.error(sb.toString(), e); withError(errorCode, errorMsg, inputParamWhereCatch); sb.clear(); for (StackTraceElement line : e.getStackTrace()) { sb.append("\tat ").append(line); } this.detailStack = sb.toString(); return (SubClass) this; } @Deprecated /** * deprecated是因为errorCode的类型改为string了 * @param errorCode * @param errorMsg * @param inputParamWhereCatch */ public <SubClass extends BaseResult> SubClass withError(int errorCode, String errorMsg, String inputParamWhereCatch) { return this.withError(errorCode + "", errorMsg, inputParamWhereCatch); } public <SubClass extends BaseResult> SubClass addWarn(String msg) { warnList.add(msg); return (SubClass) this; } public Collection<String> getWarnList() { return warnList; } public void setWarnList(Collection<String> warnList) { this.warnList = warnList; } public String toString() { return JSON.toJSONString(this); } }
package com.xxx.appmodel.domain.result; /** * 根据某id/no去数据表里查询,如果查不到时(没有故障),success为true而model为null * * @author zhoufeng * * @param <T> */ public class ModelResult<T> extends BaseResult { private static final long serialVersionUID = -1731185697573008846L; /** * 根据某id/no去数据表里查询,如果查不到时(没有故障),success为true而model为null */ private T model; private boolean readFromCache = true; // 默认值不能随便改 public ModelResult() { } public ModelResult(T model) { this.model = model; } /** * 根据某id/no去数据表里查询,如果查不到时(没有故障),success为true而model为null */ public T getModel() { return model; } public void setModel(T model) { this.model = model; } @SuppressWarnings({ "unchecked", "rawtypes" }) public <SubClass extends ModelResult> SubClass withModel(T model) { this.model = model; return (SubClass) this; } @SuppressWarnings({ "unchecked", "rawtypes" }) public <SubClass extends ModelResult> SubClass withModelFromCache(T model) { this.model = model; return (SubClass) this; } @SuppressWarnings({ "unchecked", "rawtypes" }) public <SubClass extends ModelResult> SubClass withModelFromDb(T model) { this.model = model; this.readFromCache = false; return (SubClass) this; } public boolean isReadFromCache() { return readFromCache; } public void setReadFromCache(boolean readFromCache) { this.readFromCache = readFromCache; } }
发表评论
文章已被作者锁定,不允许评论。
-
ES聚合查询大全
2020-11-18 16:16 261package com.xxx.es; import ... -
spring中使用logback日志组件替换log4j
2015-04-29 15:27 940logback比log4j的强大之处,请到logback的主页 ... -
java加密解密
2015-02-10 15:05 1724package com.neo.xnol.weixin.u ... -
eclipse常用配置
2015-01-05 11:23 1235Eclipse常用配置介绍 以 ... -
分布式事务-幂等
2014-12-30 14:04 678引用 http://www.360doc.com/conten ... -
实现基于nginx的tomcat负载均衡和集群配置
2014-12-26 16:22 1113今天看到"基于apache的tomcat负载均衡和集 ... -
java导出Excel
2014-10-14 17:00 1095package com.xxxpiao.datacompa ... -
<base target="_self"/>标签的巧妙用法
2014-10-10 15:34 743最近项目中一个小问题卡了我不少时间。我遇到的问题是:在项目的弹 ... -
分布式一致性-幂等
2014-09-28 14:53 1089关于分布式系统的数据 ... -
LDAP工具类
2014-09-05 10:12 880package com.xxxpiao.common.ut ... -
通过JNDI访问LDAP目录服务
2014-09-04 17:46 3102package com.sina.test; imp ... -
java获取两个日期之间的年月(yyyy-MM)和年月日(yyyy-MM-dd)
2014-07-29 14:42 1826public List<String> pro ... -
maven-.m2
2014-07-28 14:48 793<settings> <!--< ... -
maven实战
2014-07-07 10:04 750<settings> <!--< ... -
验证敏感词汇
2014-07-04 10:01 955package com.xxxpiao.core.memb ... -
Jms实战
2014-07-02 09:27 694<?xml version="1.0&qu ... -
互联网数功能位,表扩展(flagBit,feature)
2014-06-26 17:39 806<select id="queryRegT ... -
线程运用-抽象类使用
2014-06-26 17:34 837package com.xxx.betcart.serve ... -
JDBC分批更新
2014-06-26 17:11 616@Override public boolean ba ... -
分批查询
2014-06-26 17:08 831package com.xxxpiao.common.ut ...
相关推荐
麦克技巧将模拟的结果与观察结果进行比较。目的是一个用于对MIKE FM模型进行评分的python软件包... ModelResult:由MIKE FM输出(.dfsu或.dfs0文件)定义,可以将观测值添加到ModelResult中观察:例如点或轨迹观察指标
在编写自定义标签时,我们需要创建一个Java类来处理标签逻辑,这个类通常会继承自`javax.servlet.jsp.tagext.TagSupport`或`javax.servlet.jsp.tagext.SimpleTagSupport`。例如,我们可以创建一个名为`MyCustomTag`...
Bootstrap模态对话框是网页设计中常用的一...模态对话框由`.modal`类的`<div>`组成,包含`.modal-dialog`和`.modal-content`子元素。在这个例子中,我们还需要两个操作按钮,一个用于确定,另一个用于取消: ```html ...
var modelResult = processModel(); // 更新视图 updateView(modelResult); }); // 模型 function processModel() { // 异步获取数据 return $.ajax({ url: 'api-url', type: 'GET' }).then(function...
fmskill:将MIKE FM结果与观察结果进行比较。 是一个用于对模型进行评分的python软件包。 阅读有关更多信息。 在提出新想法或报告。用例希望在MIKE FM建模... model import ModelResult>> > from fmskill . observat