|
|
|
@@ -0,0 +1,56 @@ |
|
|
|
package com.iformall.controller.basic; |
|
|
|
|
|
|
|
import com.iformall.annotation.SystemControllerLog; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping("enum") |
|
|
|
@Api(description="枚举接口") |
|
|
|
public class EnumController { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@SystemControllerLog(description = "会员管理-标签获取") |
|
|
|
@ApiOperation(value="获取枚举对象", notes="根据获取枚举类名获取枚举对象") |
|
|
|
@GetMapping("/getEnum/{type}") |
|
|
|
public ResultData getEnum(@PathVariable("type") String type) { |
|
|
|
if(StringUtils.isBlank(type)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); |
|
|
|
} |
|
|
|
String className = "com.iformall.enums." + type; |
|
|
|
List<Map<String, String>> list = new ArrayList<Map<String, String>>(); |
|
|
|
try { |
|
|
|
// 1.得到枚举类对象 |
|
|
|
Class<Enum> clz = (Class<Enum>) Class.forName(className); |
|
|
|
// 2.得到所有枚举常量 |
|
|
|
Object[] objects = clz.getEnumConstants(); |
|
|
|
Method getCode = clz.getMethod("getCode"); |
|
|
|
Method getMessage = clz.getMethod("getMessage"); |
|
|
|
Map<String, String> map = null; |
|
|
|
for (Object obj : objects) { |
|
|
|
map = new HashMap<String, String>(); |
|
|
|
map.put("code", getCode.invoke(obj).toString()); |
|
|
|
map.put("message", getMessage.invoke(obj).toString()); |
|
|
|
list.add(map); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"数据不存在"); |
|
|
|
} |
|
|
|
if(list.size() == 0){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"数据不存在"); |
|
|
|
} |
|
|
|
return new ResultData(list); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |