mvc.SmsNoticeTimeController.java Source code

Java tutorial

Introduction

Here is the source code for mvc.SmsNoticeTimeController.java

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 mvc;

import entity.SmsNoticeTime;
import java.util.List;
import java.util.Map;
import mvc.parent.WebController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import service.SmsNoticeTimeService;
import support.ErrorMess;
import support.ServiceResult;

/**
 *
 * @author Rice Pavel
 */
@Controller
@RequestMapping("SmsNoticeTime")
public class SmsNoticeTimeController extends WebController {

    @Autowired
    private SmsNoticeTimeService service;

    @ModelAttribute
    public void setInfo(Map<String, Object> model) {
        List<SmsNoticeTime> list = service.getAll();
        model.put("list", list);
        model.put("obj", new SmsNoticeTime());
        setInfoForCommonPage(model);
    }

    @RequestMapping("/add")
    public String add(Map<String, Object> model, @ModelAttribute("obj") SmsNoticeTime obj,
            BindingResult bindingRes) {
        if (!bindingRes.hasErrors()) {
            ServiceResult res = service.save(obj);
            addErrorsToModel(model, res);
            if (!res.hasErrors()) {
                return "redirect:/SmsNoticeTime/search";
            }
        }
        return "SmsNoticeTime_search";
    }

    @RequestMapping("/delete")
    public String delete(Map<String, Object> model, String submit, @ModelAttribute("smsNoticeTimeId") Long id,
            RedirectAttributes ra) {
        try {
            service.delete(id);
        } catch (DataIntegrityViolationException e) {
            addErrorToRedirecrt(ra, ErrorMess.EXIST_RELATED_ENTITY);
        }
        return "redirect:/SmsNoticeTime/search";
    }

    @RequestMapping("/search")
    public String getAll(Map<String, Object> model) {
        return "SmsNoticeTime_search";
    }

}