Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.linln.component</groupId>
|
||||
<artifactId>thymeleaf</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>组件:thymeleaf</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.linln</groupId>
|
||||
<artifactId>component</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.linln</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.linln.modules</groupId>
|
||||
<artifactId>system</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--thymeleaf视图模板框架-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--shiro模板视图权限标签扩展-->
|
||||
<dependency>
|
||||
<groupId>com.github.theborakompanioni</groupId>
|
||||
<artifactId>thymeleaf-extras-shiro</artifactId>
|
||||
<version>${thymeleaf-shiro.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.linln.component.thymeleaf;
|
||||
|
||||
import com.linln.component.thymeleaf.attribute.SelectDictAttrProcessor;
|
||||
import com.linln.component.thymeleaf.attribute.SelectListAttrProcessor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.thymeleaf.dialect.AbstractProcessorDialect;
|
||||
import org.thymeleaf.dialect.IExpressionObjectDialect;
|
||||
import org.thymeleaf.expression.IExpressionObjectFactory;
|
||||
import org.thymeleaf.processor.IProcessor;
|
||||
import org.thymeleaf.standard.StandardDialect;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
public class TimoDialect extends AbstractProcessorDialect implements IExpressionObjectDialect {
|
||||
|
||||
private static final String NAME = "TimoDialect";
|
||||
private static final String PREFIX = "mo";
|
||||
private IExpressionObjectFactory expressionObjectFactory = null;
|
||||
|
||||
public TimoDialect() {
|
||||
super(NAME, PREFIX, StandardDialect.PROCESSOR_PRECEDENCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IProcessor> getProcessors(String dialectPrefix) {
|
||||
Set<IProcessor> processors = new LinkedHashSet<IProcessor>();
|
||||
processors.add(new SelectDictAttrProcessor(TemplateMode.HTML, dialectPrefix));
|
||||
processors.add(new SelectListAttrProcessor(TemplateMode.HTML, dialectPrefix));
|
||||
return processors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExpressionObjectFactory getExpressionObjectFactory() {
|
||||
if (this.expressionObjectFactory == null) {
|
||||
this.expressionObjectFactory = new TimoExpressionObjectFactory();
|
||||
}
|
||||
return this.expressionObjectFactory;
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.linln.component.thymeleaf;
|
||||
|
||||
import com.linln.component.thymeleaf.utility.DictUtil;
|
||||
import com.linln.component.thymeleaf.utility.LogUtil;
|
||||
import com.linln.component.thymeleaf.utility.PageUtil;
|
||||
import org.thymeleaf.context.IExpressionContext;
|
||||
import org.thymeleaf.expression.IExpressionObjectFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
public class TimoExpressionObjectFactory implements IExpressionObjectFactory {
|
||||
|
||||
public static final String PAGE_UTIL_NAME = "pageUtil";
|
||||
public static final PageUtil PAGE_UTIL_OBJECT = new PageUtil();
|
||||
public static final String DICT_UTIL_NAME = "dicts";
|
||||
public static final DictUtil DICT_UTIL_OBJECT = new DictUtil();
|
||||
public static final String LOG_UTIL_NAME = "logs";
|
||||
public static final LogUtil LOG_UTIL_OBJECT = new LogUtil();
|
||||
|
||||
@Override
|
||||
public Set<String> getAllExpressionObjectNames() {
|
||||
Set<String> names = Collections.unmodifiableSet(new LinkedHashSet<String>(Arrays.asList(
|
||||
PAGE_UTIL_NAME,
|
||||
DICT_UTIL_NAME,
|
||||
LOG_UTIL_NAME
|
||||
)));
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object buildObject(IExpressionContext context, String expressionObjectName) {
|
||||
if(PAGE_UTIL_NAME.equals(expressionObjectName)){
|
||||
return PAGE_UTIL_OBJECT;
|
||||
}
|
||||
if(DICT_UTIL_NAME.equals(expressionObjectName)){
|
||||
return DICT_UTIL_OBJECT;
|
||||
}
|
||||
if(LOG_UTIL_NAME.equals(expressionObjectName)){
|
||||
return LOG_UTIL_OBJECT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(String expressionObjectName) {
|
||||
return expressionObjectName != null;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package com.linln.component.thymeleaf.attribute;
|
||||
|
||||
import com.linln.component.thymeleaf.utility.DictUtil;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.thymeleaf.IEngineConfiguration;
|
||||
import org.thymeleaf.context.ITemplateContext;
|
||||
import org.thymeleaf.engine.AttributeName;
|
||||
import org.thymeleaf.model.IProcessableElementTag;
|
||||
import org.thymeleaf.postprocessor.IPostProcessor;
|
||||
import org.thymeleaf.processor.element.AbstractAttributeTagProcessor;
|
||||
import org.thymeleaf.processor.element.IElementTagStructureHandler;
|
||||
import org.thymeleaf.standard.expression.*;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 根据字典标识生成下拉列表
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
public class SelectDictAttrProcessor extends AbstractAttributeTagProcessor {
|
||||
|
||||
public static final int PRECEDENCE = 1400;
|
||||
public static final String ATTR_NAME = "dict";
|
||||
public static final String SELECTED_ATTR_NAME= "mo-selected";
|
||||
public static final String EMPTY_ATTR_NAME= "mo-empty";
|
||||
|
||||
public SelectDictAttrProcessor(final TemplateMode templateMode, final String dialectPrefix) {
|
||||
super(templateMode, dialectPrefix, null, false, ATTR_NAME, true, PRECEDENCE, true);
|
||||
}
|
||||
|
||||
public SelectDictAttrProcessor(final TemplateMode templateMode, final String dialectPrefix, String attrName, int precedence) {
|
||||
super(templateMode, dialectPrefix, null, false, attrName, true, precedence, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doProcess(
|
||||
final ITemplateContext context,
|
||||
final IProcessableElementTag tag,
|
||||
final AttributeName attributeName,
|
||||
final String attributeValue,
|
||||
final IElementTagStructureHandler structureHandler) {
|
||||
|
||||
// 如果属性值为空或者标签不为select,则不处理
|
||||
String elementName = tag.getElementCompleteName();
|
||||
if(attributeValue.isEmpty() || !"select".equals(elementName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取列表对象,空则不处理
|
||||
Map<String, String> valueList = DictUtil.value(attributeValue);
|
||||
if(valueList != null && valueList.size() > 0) {
|
||||
doProcess(context, tag, attributeName, attributeValue, structureHandler, valueList);
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void doProcess(
|
||||
final ITemplateContext context,
|
||||
final IProcessableElementTag tag,
|
||||
final AttributeName attributeName,
|
||||
final String attributeValue,
|
||||
final IElementTagStructureHandler structureHandler,
|
||||
Map<String, String> valueList) {
|
||||
|
||||
// 获取默认选中值
|
||||
String attributeSelectedValue = tag.getAttributeValue(SELECTED_ATTR_NAME);
|
||||
Object selectedValue = null;
|
||||
final IEngineConfiguration configuration = context.getConfiguration();
|
||||
if (attributeSelectedValue != null && !attributeSelectedValue.isEmpty()){
|
||||
final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);
|
||||
final IStandardExpression expression = expressionParser.parseExpression(context, attributeSelectedValue);
|
||||
final Object expressionResult;
|
||||
if (expression != null && expression instanceof FragmentExpression) {
|
||||
final FragmentExpression.ExecutedFragmentExpression executedFragmentExpression =
|
||||
FragmentExpression.createExecutedFragmentExpression(context, (FragmentExpression) expression);
|
||||
expressionResult =
|
||||
FragmentExpression.resolveExecutedFragmentExpression(context, executedFragmentExpression, true);
|
||||
} else {
|
||||
expressionResult = expression.execute(context, StandardExpressionExecutionContext.NORMAL);
|
||||
}
|
||||
if (expressionResult == NoOpToken.VALUE) {
|
||||
return;
|
||||
}
|
||||
selectedValue = (expressionResult == null ? "" : expressionResult);
|
||||
}
|
||||
|
||||
// 拼装下拉列表选项
|
||||
List<String> keyList = new ArrayList<>();
|
||||
if (selectedValue instanceof List){
|
||||
((List) selectedValue).forEach(item -> keyList.add(String.valueOf(item)));
|
||||
}else {
|
||||
keyList.add(selectedValue == null ? "" : selectedValue.toString());
|
||||
}
|
||||
StringBuilder optionContent = new StringBuilder();
|
||||
valueList.forEach((key, val) -> {
|
||||
optionContent.append("<option value = '").append(key);
|
||||
if(keyList.contains(String.valueOf(key))){
|
||||
optionContent.append("' ").append("selected='selected");
|
||||
}
|
||||
optionContent.append("'>").append(val).append("</option>");
|
||||
});
|
||||
|
||||
// 判断是添加空值选项
|
||||
String attributeEmptyValue = tag.getAttributeValue(EMPTY_ATTR_NAME);
|
||||
if(attributeEmptyValue != null){
|
||||
String emptyStr = "<option value=''>" + attributeEmptyValue + "</option>";
|
||||
optionContent.insert(0, emptyStr);
|
||||
}
|
||||
|
||||
// 返回新的HTML节点
|
||||
final Set<IPostProcessor> postProcessors = configuration.getPostProcessors(getTemplateMode());
|
||||
if (postProcessors.isEmpty()) {
|
||||
structureHandler.removeAttribute(SELECTED_ATTR_NAME);
|
||||
structureHandler.removeAttribute(EMPTY_ATTR_NAME);
|
||||
structureHandler.setBody(optionContent, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.linln.component.thymeleaf.attribute;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.thymeleaf.IEngineConfiguration;
|
||||
import org.thymeleaf.context.ITemplateContext;
|
||||
import org.thymeleaf.engine.AttributeName;
|
||||
import org.thymeleaf.model.IProcessableElementTag;
|
||||
import org.thymeleaf.processor.element.IElementTagStructureHandler;
|
||||
import org.thymeleaf.standard.expression.*;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 自定义下拉列表生成标签
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
public class SelectListAttrProcessor extends SelectDictAttrProcessor {
|
||||
|
||||
public static final int PRECEDENCE = 1400;
|
||||
public static final String ATTR_NAME = "list";
|
||||
|
||||
public SelectListAttrProcessor(final TemplateMode templateMode, final String dialectPrefix) {
|
||||
super(templateMode, dialectPrefix, ATTR_NAME, PRECEDENCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void doProcess(
|
||||
final ITemplateContext context,
|
||||
final IProcessableElementTag tag,
|
||||
final AttributeName attributeName,
|
||||
final String attributeValue,
|
||||
final IElementTagStructureHandler structureHandler) {
|
||||
|
||||
// 如果属性值为空或者标签不为select。则不处理
|
||||
String elementName = tag.getElementCompleteName();
|
||||
if (attributeValue.isEmpty() || !"select".equals(elementName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取列表对象
|
||||
final IEngineConfiguration configuration = context.getConfiguration();
|
||||
final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);
|
||||
final IStandardExpression expression = expressionParser.parseExpression(context, attributeValue);
|
||||
Object expressionResult;
|
||||
if (expression != null && expression instanceof FragmentExpression) {
|
||||
final FragmentExpression.ExecutedFragmentExpression executedFragmentExpression =
|
||||
FragmentExpression.createExecutedFragmentExpression(context, (FragmentExpression) expression);
|
||||
expressionResult =
|
||||
FragmentExpression.resolveExecutedFragmentExpression(context, executedFragmentExpression, true);
|
||||
} else {
|
||||
expressionResult = expression.execute(context, StandardExpressionExecutionContext.RESTRICTED);
|
||||
if (expressionResult == NoOpToken.VALUE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 转换列表对象
|
||||
Map<String, String> valueList = new LinkedHashMap<>();
|
||||
if(expressionResult.getClass().isArray()){
|
||||
// 转换数组
|
||||
int length = Array.getLength(expressionResult);
|
||||
for (int i = 0; i < length; i++) {
|
||||
String value = String.valueOf(Array.get(expressionResult, i));
|
||||
valueList.put(value, value);
|
||||
}
|
||||
}else if(expressionResult instanceof Collection){
|
||||
// 装换Collection集合
|
||||
Collection list = (Collection) expressionResult;
|
||||
list.forEach(item -> {
|
||||
valueList.put(String.valueOf(item), String.valueOf(item));
|
||||
});
|
||||
}else if(expressionResult instanceof Map){
|
||||
// 装换Map集合
|
||||
Map list = (Map) expressionResult;
|
||||
list.forEach((key, item) -> {
|
||||
valueList.put(String.valueOf(key), String.valueOf(item));
|
||||
});
|
||||
}
|
||||
|
||||
if (valueList.size() > 0) {
|
||||
doProcess(context, tag, attributeName, attributeValue, structureHandler, valueList);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.linln.component.thymeleaf.config;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* @author gion
|
||||
* @date 2021/3/19
|
||||
*/
|
||||
@ComponentScan(basePackages = "com.linln.component.thymeleaf")
|
||||
public class ThymeleafAutoConfig {
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.linln.component.thymeleaf.config;
|
||||
|
||||
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
|
||||
import com.linln.component.thymeleaf.TimoDialect;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
@Configuration
|
||||
public class ThymeleafConfig {
|
||||
|
||||
/**
|
||||
* 配置自定义的CusDialect,用于整合thymeleaf模板
|
||||
*/
|
||||
@Bean
|
||||
public TimoDialect getTimoDialect() {
|
||||
return new TimoDialect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置shiro扩展标签,用于控制权限按钮的显示
|
||||
*/
|
||||
@Bean
|
||||
public ShiroDialect shiroDialect(){
|
||||
return new ShiroDialect();
|
||||
}
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
package com.linln.component.thymeleaf.utility;
|
||||
|
||||
import com.linln.common.utils.EhCacheUtil;
|
||||
import com.linln.modules.system.domain.Dict;
|
||||
import com.linln.modules.system.service.DictService;
|
||||
import com.linln.common.utils.SpringContextUtil;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.Element;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典提取工具对象
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
public class DictUtil {
|
||||
|
||||
private static Cache dictCache = EhCacheUtil.getDictCache();
|
||||
|
||||
/**
|
||||
* 获取字典值集合
|
||||
* @param label 字典标识
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, String> value(String label){
|
||||
Map<String, String> value = null;
|
||||
Element dictEle = dictCache.get(label);
|
||||
if(dictEle != null){
|
||||
value = (Map<String, String>) dictEle.getObjectValue();
|
||||
}else {
|
||||
DictService dictService = SpringContextUtil.getBean(DictService.class);
|
||||
Dict dict = dictService.getByNameOk(label);
|
||||
if(dict != null){
|
||||
String dictValue = dict.getValue();
|
||||
String[] outerSplit = dictValue.split(",");
|
||||
value = new LinkedHashMap<>();
|
||||
for (String osp : outerSplit) {
|
||||
String[] split = osp.split(":");
|
||||
if(split.length > 1){
|
||||
value.put(split[0], split[1]);
|
||||
}
|
||||
}
|
||||
dictCache.put(new Element(dict.getName(), value));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据选项编码获取选项值
|
||||
* @param label 字典标识
|
||||
* @param code 选项编码
|
||||
*/
|
||||
public static String keyValue(String label, String code){
|
||||
Map<String, String> list = DictUtil.value(label);
|
||||
if(list != null){
|
||||
return list.get(code);
|
||||
}else{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String dataStatus(Byte status){
|
||||
String label = "DATA_STATUS";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String orderStatus(Byte status){
|
||||
String label = "ORDER_STATUS";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String payStatus(Byte status){
|
||||
String label = "PAY_STATUS";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String roleType(Byte status){
|
||||
String label = "ROLE_TYPE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String dispatchStatus(Byte status){
|
||||
String label = "DISPATCH_STATUS";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String payType(Byte status){
|
||||
String label = "PAY_TYPE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String userAmountRecordType(Byte status){
|
||||
String label = "USER_AMOUNT_RECORD_TYPE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petType(Byte status){
|
||||
String label = "PET_TYPE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petSize(Byte status){
|
||||
String label = "PET_SIZE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petHair(Byte status){
|
||||
String label = "PET_HAIR";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petVaccine(Byte status){
|
||||
String label = "PET_VACCINE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petEunuch(Byte status){
|
||||
String label = "PET_EUNUCH";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petGender(Byte status){
|
||||
String label = "PET_GENDER";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petHeadType(Byte status){
|
||||
String label = "PET_HEAD_TYPE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petCatWeight(Byte status){
|
||||
String label = "PET_CAT_WEIGHT";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String petDogWeight(Byte status){
|
||||
String label = "PET_DOG_WEIGHT";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String goodsType(Byte status){
|
||||
String label = "GOODS_TYPE";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
/**
|
||||
* 封装数据状态字典
|
||||
* @param status 状态
|
||||
*/
|
||||
public static String goodsBuyMany(Byte status){
|
||||
String label = "GOODS_BUY_MANY";
|
||||
return DictUtil.keyValue(label, String.valueOf(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存中指定的数据
|
||||
* @param label 字典标识
|
||||
*/
|
||||
public static void clearCache(String label){
|
||||
Element dictEle = dictCache.get(label);
|
||||
if (dictEle != null){
|
||||
dictCache.remove(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.linln.component.thymeleaf.utility;
|
||||
|
||||
import com.linln.common.utils.EntityBeanUtil;
|
||||
import com.linln.common.utils.SpringContextUtil;
|
||||
import com.linln.modules.system.domain.ActionLog;
|
||||
import com.linln.modules.system.service.ActionLogService;
|
||||
|
||||
import javax.persistence.Table;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author gion
|
||||
* @date 2018/10/16
|
||||
*/
|
||||
public class LogUtil {
|
||||
|
||||
/**
|
||||
* 获取实体对象的日志
|
||||
* @param entity 实体对象
|
||||
*/
|
||||
public List<ActionLog> entityList(Object entity){
|
||||
ActionLogService actionLogService = SpringContextUtil.getBean(ActionLogService.class);
|
||||
Table table = entity.getClass().getAnnotation(Table.class);
|
||||
String tableName = table.name();
|
||||
try {
|
||||
Object object = EntityBeanUtil.getField(entity, "id");
|
||||
Long entityId = Long.valueOf(String.valueOf(object));
|
||||
return actionLogService.getDataLogList(tableName, entityId);
|
||||
} catch (InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.linln.component.thymeleaf.utility;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分类显示辅助工具对象
|
||||
* @author gion
|
||||
* @date 2018/8/14
|
||||
*/
|
||||
public class PageUtil {
|
||||
|
||||
private String paramHref;
|
||||
|
||||
public boolean pageInit(Page page, HttpServletRequest request){
|
||||
if (page.getTotalElements() > page.getSize() && page.getNumberOfElements() != 0){
|
||||
|
||||
// 获取分页参数地址
|
||||
String servletPath = request.getServletPath();
|
||||
StringBuffer param = new StringBuffer(servletPath + "?");
|
||||
Enumeration em = request.getParameterNames();
|
||||
while (em.hasMoreElements()) {
|
||||
String name = (String) em.nextElement();
|
||||
if(!"page".equals(name)){
|
||||
String value = request.getParameter(name);
|
||||
param.append(name + "=" + value + "&");
|
||||
}
|
||||
}
|
||||
this.paramHref = param.toString();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> pageCode(Page page){
|
||||
int number = page.getNumber()+1;
|
||||
int totalPages = page.getTotalPages();
|
||||
int start = 0;
|
||||
int length = 7;
|
||||
int half = length % 2 == 0 ? length / 2 : length / 2 + 1;
|
||||
List<String> codeList = new ArrayList<>();
|
||||
|
||||
if(totalPages > length && number > half){
|
||||
start = number - half;
|
||||
}
|
||||
if(totalPages > length && number > totalPages - half){
|
||||
start = totalPages - length;
|
||||
}
|
||||
for (int i=1; i <= (totalPages > length ? length : totalPages); i++){
|
||||
codeList.add(String.valueOf( i + start));
|
||||
}
|
||||
if(totalPages > length && number > half){
|
||||
codeList.set(0, "1");
|
||||
codeList.set(1, "…");
|
||||
}
|
||||
if(totalPages > length && number < totalPages - (half-1)){
|
||||
codeList.set(length-2, "…");
|
||||
codeList.set(length-1, String.valueOf(totalPages));
|
||||
}
|
||||
return codeList;
|
||||
}
|
||||
|
||||
public String pageActive(Page page, String pageCode, String className){
|
||||
int number = page.getNumber();
|
||||
if(!"…".equals(pageCode)){
|
||||
if(number == Integer.valueOf(pageCode) - 1){
|
||||
return " "+className;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isPrevious(Page page){
|
||||
return page.getNumber() != 0;
|
||||
}
|
||||
|
||||
public boolean isNext(Page page){
|
||||
return page.getNumber() != page.getTotalPages() - 1;
|
||||
}
|
||||
|
||||
public boolean isCode(String pageCode){
|
||||
return "…".equals(pageCode);
|
||||
}
|
||||
|
||||
public String pageHref(String pageCode){
|
||||
return paramHref + "page=" + pageCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||
~ or more contributor license agreements. See the NOTICE file
|
||||
~ distributed with this work for additional information
|
||||
~ regarding copyright ownership. The ASF licenses this file
|
||||
~ to you under the Apache License, Version 2.0 (the
|
||||
~ "License"); you may not use this file except in compliance
|
||||
~ with the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
<dialect
|
||||
xmlns="http://www.thymeleaf.org/extras/dialect"
|
||||
prefix="mo"
|
||||
namespace-uri="https://gitee.com/aun/Timo"
|
||||
class="com.linln.component.thymeleaf.TimoDialect">
|
||||
|
||||
<!-- 自定义属性标签 -->
|
||||
<attribute-processor name="list"
|
||||
class="com.linln.component.thymeleaf.attribute.SelectListAttrProcessor">
|
||||
<documentation><![CDATA[
|
||||
自定义下拉列表生成标签,值可以为数组和集合!
|
||||
mo-selected属性:默认选择的值
|
||||
mo-empty属性:添加无值下拉选项,值为显示内容
|
||||
]]></documentation>
|
||||
</attribute-processor>
|
||||
<attribute-processor name="dict"
|
||||
class="com.linln.component.thymeleaf.attribute.SelectDictAttrProcessor">
|
||||
<documentation><![CDATA[
|
||||
根据字典标识生成下拉列表,值可以为数组和集合!
|
||||
mo-selected属性:默认选择的值
|
||||
mo-empty属性:添加无值下拉选项,值为显示内容
|
||||
]]></documentation>
|
||||
</attribute-processor>
|
||||
|
||||
<!-- 自定义对象工具 -->
|
||||
<expression-object name="pageUtil" class="com.linln.component.thymeleaf.utility.PageUtil"/>
|
||||
<expression-object name="dicts" class="com.linln.component.thymeleaf.utility.DictUtil"/>
|
||||
|
||||
|
||||
</dialect>
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.linln.component.thymeleaf.config.ThymeleafAutoConfig
|
||||
Reference in New Issue
Block a user