PostulanteController.java 1.87 KB
Newer Older
1 2 3 4 5 6
package com.roshka.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
7
import javax.validation.ConstraintViolationException;
8

9
import com.roshka.modelo.Experiencia;
10 11 12 13
import com.roshka.modelo.Postulante;
import com.roshka.repositorio.PostulanteRepository;

import org.springframework.beans.factory.annotation.Autowired;
14 15
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
16
import org.springframework.stereotype.Controller;
17 18 19 20
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
21 22 23 24 25

@Controller
public class PostulanteController {
    @Autowired
    PostulanteRepository post;  
26

27
    @RequestMapping("/")
28 29
    public String index() {
        return "index";
30 31
    }

32 33
    @RequestMapping("/postulante")
    public String getFormPostulante(){
34
        
35 36
        return "postulante-form";
    }
37

38 39
    @PostMapping(value = "/postulante",consumes = "application/json")
    public String guardarPostulante(@RequestBody Postulante postulante){
40
        post.save(postulante);
41
        return "redirect:/";
42 43
    }

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler({MethodArgumentNotValidException.class})
    public ResponseEntity<String> handleValidationExceptions(
            MethodArgumentNotValidException ex) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
                .body(ex.getMessage());
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler({ConstraintViolationException.class})
    public ResponseEntity<String> handleValidationExceptions2(
            ConstraintViolationException ex) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
                .body(ex.getMessage());
    }

60
}