Skip to content
Snippets Groups Projects
Commit c1696e3b authored by Haoyu Sun's avatar Haoyu Sun
Browse files

exchange/id fix the bugs

parent e9836e51
1 merge request!1Dev
package uk.ac.cf.spring.demo.takeaway.index;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class ExchangeController {
// page /exchangeItemList
@GetMapping("/exchange")
public ModelAndView getExchange() {
ModelAndView modelAndView = new ModelAndView("/page/itemList");
ExchangeService exchangeService =ExchangeService.getInstance();
List<ExchangeItem> exchangeItems =exchangeService.getExchangeItems();
modelAndView.addObject("exchangeItems", exchangeItems);
return modelAndView;
}
// page /exchangeItemDetail
@GetMapping("/exchange/{id}")
public ModelAndView getExchangeItem(@PathVariable Long id) {
ModelAndView modelAndView = new ModelAndView("/page/itemDetail");
ExchangeService exchangeService = ExchangeService.getInstance();
ExchangeItem exchangeItem = exchangeService.getExchangeItem(id);
modelAndView.addObject("exchangeItem", exchangeItem);
return modelAndView;
}
}
...@@ -23,6 +23,9 @@ public class ExchangeService { ...@@ -23,6 +23,9 @@ public class ExchangeService {
} }
return singleton; return singleton;
} }
public List<ExchangeItem> getExchangeItems() {
return exchangeItems;
}
// through id to search exchangeItem // through id to search exchangeItem
public ExchangeItem getExchangeItem(Long id) { public ExchangeItem getExchangeItem(Long id) {
return exchangeItems.stream().filter(exchangeItem -> return exchangeItems.stream().filter(exchangeItem ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment