package com.sx.controller;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.sx.model.Product;
import com.sx.service.ProductService;
@Controller
@RequestMapping("/demo")
public class TestController {
@Autowired
private ProductService productService;
/**
* 定义一个跳转到WEB-INF/page目录下,名为resultPage.jsp的页面
* @param request
* @return
*/
@RequestMapping("test")
public ModelAndView resultPage(HttpServletRequest request){
ModelAndView mav = new ModelAndView();
mav.addObject("info", "此信息来自DemoController 的 test方法");
mav.setViewName("resultPage");
return mav;
}
@RequestMapping("product")
public ModelAndView dbPage(HttpServletRequest request){
ModelAndView mav = new ModelAndView();
String name = request.getParameter("name");
String number = request.getParameter("number");
String type = request.getParameter("type");
Product p = new Product();
p.setPname(name);
p.setPnumber(number);
p.setPtype(type);
p.setPdate(new Date());
productService.saveObj(p);
mav.addObject("success", "保存成功");
mav.setViewName("success");
return mav;
}
}