after seeing few projects on GitHub I've been thinking, should I use static methods in my controller? I use Javalin and I created NoteController class to service all requests. What's the difference between my idea and the other one, to use static methods and don't create instance of NoteController?
public static void main(String[] args){
NoteController controller = new NoteController();
Javalin app = Javalin.create(javalinConfig -> javalinConfig.staticFiles.add("/public"))
.start();
app.routes(()-> {
path("notes", ()->{
post(controller::insertNote);
get(controller::getNotes);
delete(controller::deleteNote);
put(controller::updateNote);
});
public void insertNote(Context ctx){
database.insertNote(gson.fromJson(ctx.body(), Note.class));
ctx.status(200);
}
public void getNotes(Context ctx){
ctx.json(gson.toJson(database.getNotes(ctx.queryParam("id"))));
ctx.status(200);
}
public void deleteNote(Context ctx){
database.deleteNote(ctx.queryParam("id"));
ctx.status(200);
}
public void updateNote(Context ctx){
database.updateNote(gson.fromJson(ctx.body(), Note.class));
ctx.status(200);
}
Is my way of doing that incorrect? If I use static methods, I won't be able to use gson object as well as database instance to do database operations