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 com.MyHistory.Controller; import com.MyHistory.Service.Message.Response; import com.MyHistory.Service.Message.ResponseRegisterJugador; import com.MyHistory.Service.ServiceJugador; import java.util.Date; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; /** * * @author Alonso */ @Controller public class JugadorController { @RequestMapping(value = "/FormularioJugador", method = RequestMethod.GET) public ModelAndView desplegarFormularioJugador() { ModelAndView mv = new ModelAndView(); ServiceJugador servicio = new ServiceJugador(); ResponseRegisterJugador respuesta = servicio.obtenerDatosRegistroJugador(); mv.addObject("respuesta", respuesta); mv.setViewName("FormularioJugador"); return mv; } @RequestMapping(value = "/FormularioJugador", method = RequestMethod.POST) public ModelAndView registrarJugador(HttpServletRequest pRequest) { String pasaporte = pRequest.getParameter("Pasaporte"); String nombre = pRequest.getParameter("Nombre"); String apellido = pRequest.getParameter("Apellido"); String dia = pRequest.getParameter("day"); String mes = pRequest.getParameter("month"); String ao = pRequest.getParameter("year"); FormateadorFecha fecha_format = new FormateadorFecha(); Date fecha_nacimiento = fecha_format.getFechaDateFormat(dia, mes, ao); float altura = Float.valueOf(pRequest.getParameter("Altura")); float peso = Float.valueOf(pRequest.getParameter("Peso")); boolean activo = Integer.parseInt(pRequest.getParameter("Activo")) != 0; String pais = pRequest.getParameter("Pais"); String equipo = pRequest.getParameter("Equipo"); String posicion = pRequest.getParameter("Posicion"); System.out.println("================================================="); System.out.println("Pasaporte: "+pasaporte); System.out.println("Nombre: "+nombre); System.out.println("Apellido: "+apellido); System.out.println("Fecha nacimiento: "+fecha_nacimiento); System.out.println("Altura: "+altura); System.out.println("Peso: "+peso); System.out.println("Activo: "+activo); System.out.println("Pais: "+pais); System.out.println("Equipo: "+equipo); System.out.println("Posicion: "+posicion); System.out.println("================================================="); ServiceJugador servicio = new ServiceJugador(); Response respueta_registro = servicio.registrarJugador(pasaporte, nombre, apellido, fecha_nacimiento, altura, peso, activo, pais, equipo, posicion); ModelAndView mv = new ModelAndView(); mv.addObject("respuesta", respueta_registro.getMensaje()); mv.setViewName("redirect:/ResultadoRegistroJugador.htm"); return mv; } @RequestMapping(value = "/ResultadoRegistroJugador", method = RequestMethod.GET) public ModelAndView resultadoRegistrarJugador(HttpServletRequest pRequest) { String respuesta = pRequest.getParameter("respuesta"); ModelAndView mv = new ModelAndView(); mv.addObject("respuesta", respuesta); mv.setViewName("ResultadoRegistro"); return mv; } }