zoukankan      html  css  js  c++  java
  • Spring的controller接受Date类型数据,接受枚举类型数据

    1. Controller接收Date类型的数据

    核心使用@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 来将传递过来的时间字符串转化为Date类型

    @RestController
    @RequestMapping("res")
    public class BaseFlowController extends BaseController {
    
        private static final Logger log = LoggerFactory.getLogger(BaseFlowController.class);
    
        @Resource
        protected FamaOrderMapper orderMapper;
    
        @Resource
        private FamaUserMapper userMapper;
    
        @GetMapping("/query-all")
        @ApiException(QUERY_FLOW_FAILED)
        public Result query(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                            @RequestParam(value = "endTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
                            @RequestParam(value = "processInstanceId", required = false) Integer processInstanceId,
                            @RequestParam(value = "state", required = false) ApproveStatus state,
                            @RequestParam(value = "applyType", required = false) ApplyType applyType) {
            Map<String, Object> data = Maps.newHashMap();
            try {
                LoginContext context = LoginContext.getLoginContext();
                String user = context == null ? "xxxxxx" : context.getPin();
                QueryWrapper<FamaUser> queryWrapper = Wrappers.query();
                queryWrapper.eq("erp",user);
                queryWrapper.eq("role_type", RoleType.SYS_ADMIN);
                FamaUser admin = userMapper.selectOne(queryWrapper);
                if (Optional.ofNullable(admin).isPresent()) {
                    user = "";
                }
                List<FamaOrder> orders = orderMapper.selectByParam(user, start, end, applyType, processInstanceId, state);
                List<QueryResult> queryResults = ModuleHelper.mapAll(orders, QueryResult.class);
                queryResults.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime()));
                data.put(Constants.DATA_LIST, queryResults);
                data.put(Constants.STATUS, SUCCESS);
                data.put(Constants.MSG, SUCCESS.getMsg());
            } catch (Exception e) {
                log.warn("create xbp order failed", e);
                data.put(Constants.STATUS, QUERY_FLOW_FAILED);
                data.put(Constants.MSG, QUERY_FLOW_FAILED.getMsg());
            }
            return returnDataList(data);
        }
    }
    

    2.Controller 接收枚举类型数据

    EnvType env,直接进行映射,不需要再别的操作

    @GetMapping(value = "/query-details-instance-types-cost-times")
        public Result queryDetailsInstanceTypesCostTimes(
                @RequestParam("env") EnvType env,
                @RequestParam("instanceId") String instanceId,
                @RequestParam("regionId") String regionId) {
            Map<String, Object> data;
            try {
                RdsContext context = RdsContext.builder().setEnvType(env).setRegionId(regionId).setInstanceId(instanceId).build();
                RdsRegionGetter getter = RdsRegionGetter.newInstance(context);
                data = getter.queryDetailsInstanceTypesCostTimes();
            } catch (Exception e) {
                logger.error("query-details-instance-types", e);
                data = Maps.newHashMap();
            }
            return returnDataList(data);
        }
    
  • 相关阅读:
    软件设计师-成绩查询
    spring data jpa
    Maven 项目中使用 logback
    spring boot 整合 Camunda
    Spring 中 bean 的生命周期?
    如何合理的使用工具提高效率?
    Java 中的日志
    HashMap 原理?jdk1.7 与 1.8区别
    内存泄漏与溢出
    v-on 绑定自定义事件
  • 原文地址:https://www.cnblogs.com/PythonOrg/p/14836033.html
Copyright © 2011-2022 走看看