productaddformcontroller.java

来自「这个是我做j2ee培训的一个spring mvc的例子」· Java 代码 · 共 48 行

JAVA
48
字号
package org.hyq.springapp.spring.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hyq.springapp.bus.Product;
import org.hyq.springapp.bus.ProductManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

public class ProductAddFormController extends SimpleFormController {
	/** Logger for this class and subclasses */
	protected final Log logger = LogFactory.getLog(getClass());

	private ProductManager prodMan;

	public ModelAndView onSubmit(Object command) throws ServletException {

		Product p = (Product)command;

		logger.info("Add Product");
		prodMan.addProduct( p );
		logger.info("returning from PriceIncreaseForm view to "
				+ getSuccessView());
		//return new ModelAndView(new RedirectView("index.jsp"));
		return new ModelAndView(new RedirectView(getSuccessView()));
		//return new ModelAndView("index.jsp");
	}

	protected Object formBackingObject(HttpServletRequest request)
			throws ServletException {
		Product product = new Product();
		product.setPrice( new Double( 0.0 ) );
		return product;
	}

	public void setProductManager(ProductManager pm) {
		prodMan = pm;
	}

	public ProductManager getProductManager() {
		return prodMan;
	}
}

⌨️ 快捷键说明

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