Java tutorial
/* * 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 br.com.arduinoweb.controller; import br.com.arduinoweb.model.Page; import br.com.arduinoweb.model.Profile; import br.com.arduinoweb.model.User; import br.com.arduinoweb.service.CommandService; import br.com.arduinoweb.service.OutputService; import br.com.arduinoweb.service.PageService; import br.com.arduinoweb.service.ProfileService; import br.com.arduinoweb.service.UserService; import java.io.IOException; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; /** * * @author Rodolfo */ @Controller public class AdminController { //<editor-fold defaultstate="collapsed" desc="Home"> @RequestMapping("/Home") public ModelAndView Home(HttpSession session, HttpServletResponse response) throws IOException { ModelAndView mv = new ModelAndView("User/Home"); new OutputService().ChangeOutputByList(session); mv.addObject("listCommand", new CommandService().getCommandShow()); return mv; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Profile"> @RequestMapping("/Profile") public ModelAndView Profile(HttpSession session) { ModelAndView mv = new ModelAndView("Admin/Profile"); mv.addObject("profiles", new ProfileService().getProfiles()); return mv; } @RequestMapping("actions/deleteProfile") public ModelAndView deleteProfile(Profile profile) throws SQLException { ModelAndView mv = new ModelAndView("redirect:/Profile"); mv.addObject("Message", new ProfileService().DeleteProfile(profile)); return mv; } @RequestMapping("actions/saveProfile") public ModelAndView saveProfile(Profile profile) throws SQLException { ModelAndView mv = new ModelAndView("redirect:/Profile"); mv.addObject("Message", new ProfileService().SaveProfile(profile)); return mv; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="ProfilePage"> @RequestMapping("/ProfilePage") public ModelAndView ProfilePage(HttpSession session) { ModelAndView mv = new ModelAndView("Admin/ProfilePage"); mv.addObject("listPages", new PageService().getPages()); mv.addObject("profilesPage", new ProfileService().getProfiles()); return mv; } @RequestMapping("actions/getPagebyIdProfile") public @ResponseBody String PageByProfileId(@RequestParam(value = "id") String id) { return new ProfileService().getPageConcatByProfileId(Integer.parseInt(id)); } @RequestMapping("actions/saveProfilePage") public ModelAndView savaProfilePage(HttpServletRequest request, Profile profile) throws SQLException { ModelAndView mv = new ModelAndView("redirect:/ProfilePage"); String id[] = request.getParameterValues("pageId"); mv.addObject("Message", new ProfileService().ChangeProfile(profile, id)); return mv; } @RequestMapping("actions/deletePageProfile") public ModelAndView savaProfilePage(Page page, Profile profile) throws SQLException { ModelAndView mv = new ModelAndView("redirect:/ProfilePage"); mv.addObject("Message", new ProfileService().DeleteProfilePage(profile, page)); return mv; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Users"> @RequestMapping("/Users") public ModelAndView Users(HttpSession session) { ModelAndView mv = new ModelAndView("Admin/Users"); mv.addObject("listProfile", new ProfileService().getProfiles()); mv.addObject("listUsers", new UserService().getUsers()); return mv; } @RequestMapping("actions/deleteUsers") public ModelAndView deleteUsuario(User user) throws SQLException { ModelAndView mv = new ModelAndView("redirect:/Users"); mv.addObject("Message", new UserService().DeleteUser(user)); return mv; } @RequestMapping("actions/saveProfileUser") public ModelAndView saveUsuario(User user, HttpServletRequest request) throws SQLException { ModelAndView mv = new ModelAndView("redirect:/Users"); String[] idProfile = request.getParameterValues("profileId"); int profileId = Integer.parseInt(idProfile[0]); mv.addObject("Message", new UserService().SaveUser(user, profileId)); return mv; } //</editor-fold> }