Package net.viralpatel.contact.controller

Source Code of net.viralpatel.contact.controller.ContactController

package net.viralpatel.contact.controller;

import java.util.Map;

import net.viralpatel.contact.form.Contact;
import net.viralpatel.contact.service.ContactService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ContactController {

  @Autowired
  private ContactService contactService;

  @RequestMapping("/index")
  public String listContacts(Map<String, Object> map) {

    map.put("contact", new Contact());
    map.put("contactList", contactService.listContact());

    return "contact";
  }

  @RequestMapping(value = "/add", method = RequestMethod.POST)
  public String addContact(@ModelAttribute("contact")
  Contact contact, BindingResult result) {

    contactService.addContact(contact);

    return "redirect:/index";
  }

  @RequestMapping("/delete/{contactId}")
  public String deleteContact(@PathVariable("contactId")
  Integer contactId) {

    contactService.removeContact(contactId);

    return "redirect:/index";
  }
}
TOP

Related Classes of net.viralpatel.contact.controller.ContactController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.