小编use*_*rch的帖子

减少方法中的返回语句数

我有一个java代码,其中单个方法中有多个return语句.但是出于代码清理的目的,每个方法只能有一个return语句.可以做些什么来克服这一点.

这是我的代码中的方法: -

public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

        // Kill any old sessions
        //request.getSession().invalidate();
        DynaValidatorForm dynaform = (DynaValidatorForm)form;

        // validate the form
        ActionErrors errors = form.validate(mapping, request);
        if(!errors.isEmpty()) {
            this.saveErrors(request, errors);
            return mapping.getInputForward();
        }

        // first check if token is set
        if(!isTokenValid(request, true)) {
            String errmsg="There was a problem with your login. Please close your browser then reopen it and try again. Make sure to click the Login button only ONCE.";
            request.setAttribute("errormessage", …
Run Code Online (Sandbox Code Playgroud)

java return code-cleanup

7
推荐指数
3
解决办法
2015
查看次数

标签 统计

code-cleanup ×1

java ×1

return ×1