0

I'm trying to call a url with an ID between /.

The url looks like this: http://localhost:8080/chargeback/v1/dispute/22/events

and I need to recover that value 22 in the sysout from controller.

I know thats sounds very easy, but in my project i'm trying fix that w/ other programmers for many time. Maybe some configuration i forgot.

Interface:

@RequestMapping("/dispute")
public interface disputeEvents{

    @GetMapping( value = "/{id}/events")
    ResponseEntity<Void> getDisputeEvents(@RequestParam Long id);

}

controller:

@Controller
public class testeController implements disputeEvents{

    @Override
    public ResponseEntity<Void> getDisputeEvents(Long id) {
    System.out.println(id);
    return null;
    }
}

2 Answers2

0

Change your interface and class as shown below code.

@RequestMapping("/default")
public interface disputeEvents {

    @GetMapping("/{id}/events")
    ResponseEntity<Void> getDisputeEvents(@PathVariable Long id);

}
@Controller
@RequestMapping("/dispute")
public class testeController implements disputeEvents {

    @Override
    public ResponseEntity<Void> getDisputeEvents(Long id) {
        System.out.println(id);
        return null;
    }
}

It will work fine for URL:http://localhost:8080/dispute/22/events. If you want it to work for Url:http://localhost:8080/chargeback/v1/dispute/22/events, Change @RequestMapping("/dispute") to @RequestMapping("/chargeback/v1/dispute") in your controller class.

  • I tried as you said and it didn't work. My code normally accesses the controller class/method, but when printing the value returns null. – Henrique Landim Jan 12 '21 at 12:06
  • It will work, Please check your interface and class once again maybe you have done any mistake because the Long value can't be null. Be sure that you have used @GetMapping( value = "/{id}/events") in interface not in the class. – Ajit Kumar Singh Jan 12 '21 at 17:23
0

I put the @GetMapping("/{id}/events") inside controller.

Interface:

@RequestMapping("/default")
public interface disputeEvents {
    @GetMapping( value = "/{id}/events")
    ResponseEntity<Void> getDisputeEvents(@PathVariable(name = "id") Long id);
}

Controller:

@Controller
@RequestMapping("/dispute")
public class testeController implements disputeEvents{
    @Override
    public ResponseEntity<Void> getDisputeEvents(@PathVariable(name = "id") Long id) {  
        System.out.println("teste:" + id);
        return null;
    }

}