Skip to content

Instantly share code, notes, and snippets.

@nikhil3000
Last active June 24, 2020 18:01
Show Gist options
  • Save nikhil3000/5059500276909ca771405a12c717ccf0 to your computer and use it in GitHub Desktop.
Save nikhil3000/5059500276909ca771405a12c717ccf0 to your computer and use it in GitHub Desktop.
@Path("/data")
@Produces(MediaType.APPLICATION_JSON)
public class Route {
MyDAO dao;
public Route(Jdbi jdbi) {
dao = jdbi.onDemand(MyDAO.class);
try {
dao.testQuery();
} catch (Exception e) {
dao.createUserTable();
}
}
@POST
@Path("/post")
@Consumes({ MediaType.APPLICATION_JSON })
public boolean setData(User user) {
dao.insert(user.getid(), user.getName());
return true;
}
@GET
@Path("/get/{id}")
public String getDataById(@PathParam("id") Integer id) {
String name = dao.findNameById(id);
return name;
}
@GET
@Path("/get")
public String getAllData() {
List<String> list = dao.getAllNames();
String str = new Gson().toJson(list);
return str;
}
@GET
@Path("/test")
public String getData() {
String s = "Hello world";
return s;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment