0

Im running an app in Java (springboot) for the backend and angularJs for the front end. I´m having some trouble making the POST/PUT methods work. There are no errors on the post method in the angularjs part but my java code might be broken, it can´t reach the DB, tells me everything is okey but the data doesnt update.

Heres the angularjs method:

        .controller(
            'TecnicoController',
            [
                '$scope',
                '$http',
                '$routeParams',
                function($scope, $http, $routeParams) {

                        var onError = function(reason) {
                            $scope.error = "No se pudo encontrar";
                        };

                        var urlbase = "http://localhost:8080/";

                        var legajo = $routeParams.legajo;

                        console.log(legajo);

                        var onTecnicoComplete = function(response) {
                            $scope.tecnico = response.data;
                            console.log($scope.tecnico);
                        };

                        console.log($scope.tecnico);

                        $http.get(urlbase + "get/tecnico/" + legajo)
                                .then(onTecnicoComplete, onError);

                        $scope.saveTecnico = function(tecnico) {
                            console.log(tecnico);
                            return $http.post(urlbase + "set/tecnico/",        tecnico)

                        };

                    } ])

The get methods work like a charm and I get the OK in the log after doing the post Console log

Heres my JAVA code for the Controller I´ll upload the service serviceimpl and repository if needed.

   @RestController
   public class TecnicoController {

@Autowired
TecnicoRepository tecnicoRepository;

@Autowired
private final TecnicoService tecnicoService;

@Inject
public TecnicoController(final TecnicoService tecnicoService) {
    this.tecnicoService = tecnicoService;
}

@RequestMapping(value = "/get/tecnico/{legajo}", method = RequestMethod.GET)
@ResponseBody
public Object queryTecnico(@PathVariable Integer legajo) {
    Tecnico tecnico = tecnicoService.getTecnico(legajo);
    if (tecnico == null)
        return "No encontrado";
    return tecnico;
}

@RequestMapping(value = "/get/tecnico/", method = RequestMethod.GET)
@ResponseBody
public Object queryTecnico() {
    List<Tecnico> tecnico = tecnicoRepository.findAll();
    return tecnico;
}

@RequestMapping(value = "/set/tecnico/", method = RequestMethod.POST)
@Transactional
public Tecnico editTecnico(final Tecnico tecnico) {
    return tecnicoRepository.save(tecnico);
}

**EDIT: Screenshot of the debug when the method runs:

IDE DEBUG

Not sure why it´s not working... I kinda going through the spring manual to see if I can fix it but it´s making me crazy and time is of the essence.

Heres the HTML just in case:

       <form role="form">
<div class="panel-body">

    <div class="panel-body">
        <img src="/assets/doge.jpg" alt="Doge">
    </div>

    <div class="container">
        <div class="input-group">
            <span class="input-group-addon" id="tec-nombre">Nombre del
                Tecnico:</span><input type="text" class="form-control"
                data-ng-model="tecnico.nombre" aria-describedby="tec-nombre">
        </div>
        <div class="input-group">
            <span class="input-group-addon" id="tec-legajo">Legajo del
                Tecnico:</span><input type="number" class="form-control"
                data-ng-model="tecnico.legajo" aria-describedby="tec-legajo">
            <div role="alert">
                <span class="error"
                    data-ng-show="myForm.legajoTecnico.$error.required">
                    Required!</span>
            </div>
        </div>
        <div class="input-group">
            <span class="input-group-addon" id="tec-email">Email del
                Tecnico:</span><input type="email" class="form-control"
                data-ng-model="tecnico.email" aria-describedby="tec-email">
            <div role="alert">
                <span class="error"
                    data-ng-show="myForm.emailTecnico.$error.required">
                    Required!</span>
            </div>
        </div>
        <div class="input-group">
            <span class="input-group-addon" id="tec-interno">Interno del
                Tecnico:</span><input type="text" class="form-control"
                data-ng-model="tecnico.interno" aria-describedby="tec-interno">
            <div role="alert">
                <span class="error"
                    data-ng-show="myForm.nombreTecnico.$error.required">
                    Required!</span>
            </div>
        </div>
    </div>
</div>
<div class= "form-group">
<label class= "col-md-2"></label>
<div class="col-md-4">
<a href="#/" class="btn">Cancel</a>
    <button data-ng-click="saveTecnico(tecnico);" 
             class="btn btn-primary">Actualizar {{tecnico.legajo}}</button>
    <button data-ng-click="deleteCustomer(customer)"
            data-ng-show="customer._id" class="btn btn-warning">Delete</button>
</div>

2
  • What is the error you are getting? Commented Nov 13, 2015 at 15:30
  • No error it´s just not working, it can´t reach the DB. Commented Nov 13, 2015 at 15:32

1 Answer 1

1

You need to annotate the parameter with @RequestBody:

public Tecnico editTecnico(final @RequestBody Tecnico tecnico) {
    return tecnicoRepository.save(tecnico);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sir you just won the internet. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.