以下代码的可调用命令设计模式解决方案

时间:2019-05-30 09:21:39

标签: java design-patterns

我有下面的代码块,我想使用Callable设计模式避免重复的代码。有可能吗?

    @GetMapping("")
    public ResponseEntity<?> getUserRules(HttpServletRequest request)
    {
        String integId = helper.getIntegId(request);
        String orgId = helper.getOrgId(request);
        return ResponseEntity.ok(service.getUserRules(integId,    orgId));
    }

    @GetMapping("/{ruleId}")
    public ResponseEntity<?> getRule(HttpServletRequest request, @PathVariable Long ruleId)
    {
        String integId = helper.getIntegId(request);
        String orgId = helper.getOrgId(request);
        return ResponseEntity.ok(service.getRule(integId, orgId, ruleId));
    }

    @PutMapping("/{ruleId}")
    public ResponseEntity<?> updateRule(HttpServletRequest request, @PathVariable Long ruleId,
                                        @RequestBody @Valid Object object)
    {
        String integId = helper.getIntegId(request);
        String orgId = helper.getOrgId(request);
        service.updateRule(integId, orgId, ruleId, object);
        return ApiResponse.ok();
    }

我想尝试使用Callable方法执行它。

public ResponseEntity execute(HttpServletRequest request)
{
    ? Actually, I could not find an exact solution here.
}

0 个答案:

没有答案