code

2019-02-07 11:14:38.243

package com.controller;


import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;


import com.bean.OrderBean;

import com.service.OrderService;


@Controller

public class OrderController {


@Autowired

private OrderService service;

@RequestMapping("/placeorder1.htm")

public ModelAndView diaplayOrderForm()

{

System.out.println("in disp");

OrderBean order=new OrderBean();

ModelMap map=new ModelMap();

map.addAttribute(order);

ModelAndView mv=new ModelAndView();

mv.setViewName("order");

return mv;

}


@ModelAttribute("productList")

public List<Integer> populateProductId()

{

List<Integer> list = null;

try {

list = service.getAllProducts();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

@RequestMapping("/ordering.htm")

public ModelAndView saveOrder(@ModelAttribute OrderBean orderbean)

{

ModelAndView mv=new ModelAndView();

try {

OrderBean order= service.saveOrder(orderbean);

mv.addObject(order);

mv.setViewName("order");

} catch (Exception e) {

// TODO Auto-generated catch block

mv.addObject("error", "failed"+e.getMessage() );

mv.setViewName("order");

return mv;

}

return mv;

}

}