Code changes
This commit is contained in:
parent
d37f95b991
commit
10ae695227
|
@ -92,7 +92,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
|
|
|
@ -28,7 +28,7 @@ public final class TakesApp {
|
|||
new TkFallback(
|
||||
new TkSlf4j(
|
||||
new TkFork(
|
||||
new FkRegex("/", "Hello, World!"),
|
||||
new FkRegex("/", new TakesHelloWorld()),
|
||||
new FkRegex("/index", new TakesIndex()),
|
||||
new FkRegex("/contact", new TakesContact()),
|
||||
new FkRegex("/createUser", new TakesCreateUser(TakesApp.dbConnection())),
|
||||
|
@ -46,8 +46,7 @@ public final class TakesApp {
|
|||
);
|
||||
}
|
||||
})
|
||||
),
|
||||
6060
|
||||
), 6060
|
||||
).start(Exit.NEVER);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package com.baeldung.takes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.takes.Request;
|
||||
import org.takes.Response;
|
||||
import org.takes.Take;
|
||||
|
@ -13,7 +10,7 @@ import org.takes.rs.RsWithType;
|
|||
public final class TakesContact implements Take {
|
||||
|
||||
@Override
|
||||
public Response act(Request req) throws IOException, SQLException {
|
||||
public Response act(Request req) {
|
||||
return new RsWithStatus(new RsWithType(new RsWithBody("<html>"
|
||||
+ "<head>"
|
||||
+ "<title>Takes Application - Contact</title></head>"
|
||||
|
@ -22,5 +19,4 @@ public final class TakesContact implements Take {
|
|||
+ "</body></html>"), "text/html"), 200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public final class TakesCreateUser implements Take {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Response act(final Request req) throws IOException, SQLException {
|
||||
public Response act(final Request req) throws IOException {
|
||||
|
||||
RqForm form = new RqFormSmart(req);
|
||||
Iterable<String> idParam = form.param("id");
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.takes.Response;
|
|||
import org.takes.Take;
|
||||
import org.takes.rs.RsText;
|
||||
|
||||
public final class TkRoute implements Take {
|
||||
public class TakesHelloWorld implements Take {
|
||||
|
||||
@Override
|
||||
public Response act(final Request request) {
|
|
@ -1,7 +1,6 @@
|
|||
package com.baeldung.takes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.takes.Request;
|
||||
import org.takes.Response;
|
||||
|
@ -12,7 +11,7 @@ import org.takes.rs.RsVelocity;
|
|||
public final class TakesIndex implements Take {
|
||||
|
||||
@Override
|
||||
public Response act(final Request req) throws IOException, SQLException {
|
||||
public Response act(final Request req) throws IOException {
|
||||
|
||||
return new RsHtml(new RsVelocity(this.getClass().getResource("/templates/index.vm") ,new RsVelocity.Pair("userName", "Anshul")));
|
||||
}
|
||||
|
|
|
@ -18,15 +18,15 @@ import org.takes.rs.RsJson;
|
|||
|
||||
|
||||
public final class TakesReadUser implements Take {
|
||||
|
||||
|
||||
public static Connection con;
|
||||
|
||||
|
||||
TakesReadUser(Connection connection) {
|
||||
con = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response act(final Request req) throws IOException, SQLException {
|
||||
public Response act(final Request req) throws IOException {
|
||||
Href href = new RqHref.Base(req).href();
|
||||
Iterable<String> ids = href.param("id");
|
||||
int id = Integer.parseInt((String) ids.iterator().next());
|
||||
|
@ -43,7 +43,7 @@ public final class TakesReadUser implements Take {
|
|||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return new RsJson(json);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue