补充https://blog.csdn.net/qq_37148232/article/details/138303873?spm=1001.2014.3001.5501
通用工具类:
@SuppressWarnings("ALL")
public class Share {public static <T> void set(String key, T value) {HttpServletRequest request = ZYRequestUtils.getRequest();if (null != request && null != key && null != value) {request.setAttribute(key, value);}}public static <T> T get(String key, Class<T> aClass) {HttpServletRequest request = ZYRequestUtils.getRequest();if (null == request) {return null;}if (null == key) {return null;}Object attribute = request.getAttribute(key);return null != attribute ? (T) attribute : null;}public static <T> List<T> getList(String key, Class<T> aClass) {HttpServletRequest request = ZYRequestUtils.getRequest();if (null == request) {return null;}if (null == key) {return null;}Object attribute = request.getAttribute(key);return null != attribute ? (List<T>) attribute : new ArrayList<>();}public static <T> Map<String, T> getMap(String key, Class<T> aClass) {HttpServletRequest request = ZYRequestUtils.getRequest();if (null == request) {return null;}if (null == key) {return null;}Object attribute = request.getAttribute(key);return null != attribute ? (Map<String, T>) attribute : new HashMap<>();}public static void remove(String key) {HttpServletRequest request = ZYRequestUtils.getRequest();if (null != request) {request.removeAttribute(key);}}
}
对字典类型处理器的一个小小改造。查询集合时,让相同的字典对象不重复查询缓存。且相同的字典属性指向同一个对象。对于字典字段较多的(比如用户),可以减少对象的创建数量。(算是很无聊的一个改造了)。
public class DictTypeHandler extends MyTypeHandler<DictColumn> {@Overridepublic String getSetValue(DictColumn dictColumn) {return null != dictColumn ? dictColumn.getValue() : null;}@Overridepublic DictColumn buildResultModel(String dictValue, String columnName) {if (ZYStrUtils.isAnyNull(dictValue, columnName)) {return new DictColumn();}String dictCode = columnName.toLowerCase();String key = dictCode + dictValue;DictColumn dictColumn = Share.get(key, DictColumn.class);if (null == dictColumn) {dictColumn = new DictColumn();dictColumn.setDictCode(dictCode);dictColumn.setValue(dictValue);// 该行代码会触发读取redis缓存dictColumn.setLabel(ZYDictHelper.dictName(dictCode, dictValue));Share.set(key, dictColumn);}return dictColumn;}
}