Package ru.drakeface.springmvchibernate.web

Source Code of ru.drakeface.springmvchibernate.web.ContactController

/*
$Author$
$Date$
$Revision$
$Source$
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ru.drakeface.springmvchibernate.web;

import java.util.Map;
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;
import ru.drakeface.springmvchibernate.domain.Contact;
import ru.drakeface.springmvchibernate.service.ContactService;

/**
*
* @author ivc_ShherbakovIV
*/
@Controller
/*
��������� ������������ ��� ����������� ����������� ������ java ������ � ����� �����������.
������ ����� ������������ ����� ���������, ������� �� ������� ������� (HttpServlet) (���������� � ��������� HttpServletRequest � HttpServletResponse),
�� � ������������ ������������� �� ���������� � MVC-�����������.
*/
public class ContactController {

    @Autowired
    private ContactService contactService;

    @RequestMapping("/index")
    /*
     ��������� ������������ ��� �������� ���-������ ������� �� ��������� ����� ��� �����.
     ������ ����� ������� ��� �� ����� ������, ��� � �� ����� �����.
     ����������� ��������� ���������� HTTP-�����, ������� ����� �������������� (GET/POST), ���������� ��������� �������.
     */
    public String listContacts(Map<String, Object> map) {

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

        return "contact2";
    }

    @RequestMapping("/")
    public String home() {
        return "redirect:/index";
    }

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

        contactService.addContact(contact);

        return "redirect:/index";
    }

    @RequestMapping("/delete/{contactId}")
    /*
     @PathVariable
     ���������, ������� ����������, ��� �������� ������ ������ ���� ������ � ���������� �� ���-������.
     */
    public String deleteContact(@PathVariable("contactId") Integer contactId) {

        contactService.removeContact(contactId);

        return "redirect:/index";
    }
}
TOP

Related Classes of ru.drakeface.springmvchibernate.web.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.