Skip to content

Instantly share code, notes, and snippets.

@maggandalf
Created April 20, 2011 17:07
Show Gist options
  • Save maggandalf/931966 to your computer and use it in GitHub Desktop.
Save maggandalf/931966 to your computer and use it in GitHub Desktop.
Home Controller for Trading Service.
@Controller
public class HomeController {
@Autowired
private TradingService tradingService;
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value="/", method=RequestMethod.GET)
public String showForm(Model model) {
model.addAttribute("stockInfo", new StockForm());
return "newstock";
}
/**
* Simply gets a new stock and shows current status.
* @return view.
*/
@RequestMapping(value="/", method=RequestMethod.POST )
public ModelAndView submitForm(@ModelAttribute("stockInfo")StockForm stockForm) {
Stock stock = getStock(stockForm.getName(), stockForm.getThreshold());
stock.setTradeAt(stockForm.getTradeAt());
return new ModelAndView("showstatus", "status", stock.getStatus());
}
public Stock getStock(String name, double threshold) {
return this.tradingService.addNewStock(name, threshold);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment