Last active
June 24, 2020 18:01
-
-
Save nikhil3000/5059500276909ca771405a12c717ccf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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