コード例 #1
0
 @RequestMapping("/produk/list")
 public ModelMap daftarProduk() throws Exception {
   List<Produk> hasil = produkDao.cariSemuaProduk();
   ModelMap mm = new ModelMap();
   mm.addAttribute("daftarProduk", hasil);
   return mm;
 }
コード例 #2
0
 @RequestMapping("/produk/delete")
 public String hapusProduk(@RequestParam Integer id) {
   try {
     produkDao.hapus(id);
   } catch (Exception err) {
     System.out.println("Gagal hapus : " + err.getMessage());
   }
   return "redirect:list";
 }
コード例 #3
0
  @RequestMapping(value = "/produk/form", method = RequestMethod.GET)
  public ModelMap tampilkanFormProduk(@RequestParam(required = false) Integer id) throws Exception {
    System.out.println("Menampilkan Form Produk");

    Produk p = produkDao.cariById(id);

    if (p == null) {
      p = new Produk();
    }

    ModelMap mm = new ModelMap();
    mm.addAttribute("produk", p);
    return mm;
  }
コード例 #4
0
  @RequestMapping(value = "/produk/form", method = RequestMethod.POST)
  public String prosesFormProduk(
      @ModelAttribute @Valid Produk p, BindingResult hasilValidasi, SessionStatus status)
      throws Exception {

    p.setTerakhirUpdate(new Date());

    if (hasilValidasi.hasErrors()) {
      return "/produk/form";
    }

    produkDao.simpan(p);
    status.setComplete();
    return "redirect:list";
  }