0
So, guys, I’m developing a mini framework for study purposes, using the Java front controller, and I came across the following problem.
First of all I’ll explain how it’s working.
I embed the Jetty server inside the framework, when I open my application (using the mini-framework) it will scan the classes of my project check if there are two annotations that I created in my classes that are @Rest
(defines the class as a controller) and @Get
(maps the request) and plays in a hashMap with the mapping as key and the controller class as value.
@Rest
public class UserController {
@Get("/books")
public String getBook() {
Book book = new Book();
book.setAuthor("NetoDevel");
book.setTitle("RileyFramework");
book.setPrice(0.0d);
return JsonReturn.toJson(book);
}
@Get("/book/:id")
public String findOne(String id) {
return id;
}
}
When I receive the request, I play it in the key of my map and I take the value that is the controller class and I invoke the beauty method?
So far everything works perfectly, but I want to set parameters in my URI, in REST architecture.
Format I want to implement:
http://localhost:8080/books/:id
and not
http://localhost:8080/books?id=1
My question is: How to get there in my Serrvlet that is implemented the value of :id
?
I can have more than one stop in this format below:
http://localhost:8080/books/:id/author/:id
Follow the project link on github: https://github.com/NetoDevel/riley-framework
The answer helped you or needs more details?
– Murillo Goulart