Home > Software design >  I'm using Java Spring framework to map data from a portion of my data and my pathvariable won&#
I'm using Java Spring framework to map data from a portion of my data and my pathvariable won&#

Time:03-23

I'm using the Java Spring framework to map data from a portion of my data and my @pathvariable won't get me access to any data. all I;m getting in the console is bash: localhost:4001/traveladventures/bycountry/Greece: No such file or directory

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;

  @GetMapping()
  public Iterable<Adventure> getAllAdventures(){
    return this.adventureRepository.findAll();
  }

  @GetMapping("/bycountry/{country}")
  public List<Adventure> getByCountry(@PathVariable("country") String country){
    return this.adventureRepository.findByCountry(country);
  }

my data is comming in through sql and I'm using this interface to get access to the data

public interface AdventureRepository extends CrudRepository<Adventure, Integer> {
  public List<Adventure> findByCountry(String country);
  public List<Adventure> findByState(String state);
}

CodePudding user response:

Try This command

Blockquote

curl -v http://localhost:4001/traveladventures/bycountry/Greece

CodePudding user response:

Can you confirm whether you get the value of the country inside this getByCountry()method (by either logging or debugging) or it's not even hitting the API? Also, please check the path of the API as well. Is the first Get API working?

Also one suggestion, Controller is basically a dumb entry point of the API, all business logic must be implemented in the Service layer. The controller just passes the incoming values to the service layer.

  • Related