Created
April 20, 2011 17:07
-
-
Save maggandalf/931966 to your computer and use it in GitHub Desktop.
Home Controller for Trading Service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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