addcatfc.java

来自「sping下勇Xdoclet开发hibernate的程序实例,版本hiberna」· Java 代码 · 共 53 行

JAVA
53
字号
package org.ggyy.web.ctrl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ggyy.bo.Cat;
import org.ggyy.web.cmd.CatCmd;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

/**
 * 
 * spring的控制器,类似于struts的Action
 *
 */
/**
 * @author jiangyubao
 * @spring.bean id="addCatFC"
 * @spring.property name="catDao" ref="catDao"
 * @spring.property name="validator" ref="catFVLD"
 * @spring.property name="formView" value="catForm.jsp"
 * @spring.property name="sessionForm" value="true"
 */
public class AddCatFC extends AbstractPetFC {

    public AddCatFC() {
        this.setCommandClass(Cat.class);
    }

    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {
        String parentId = request.getParameter("parentId");
        Cat parent = null;
        if (parentId != null && !parentId.equals("")) {
            parent = (Cat) this.getCatDao().load(parentId);
        }
        Cat cat = (Cat) command;
        cat.setParent(parent);
        this.getCatDao().store(cat);
        return new ModelAndView(new RedirectView("listCat.sf"), "parentId", cat
                .getParent() != null ? cat.getParent().getId() + "" : cat
                .getId()
                + "");

    }

    protected ModelAndView handleInvalidSubmit(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        return this.disallowDuplicateFormSubmission(request, response);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?