Code changes

This commit is contained in:
Anshul BANSAL 2020-02-22 16:19:02 +02:00
parent d37f95b991
commit 10ae695227
7 changed files with 11 additions and 17 deletions

View File

@ -92,7 +92,7 @@
<dependency> <dependency>
<groupId>org.apache.velocity</groupId> <groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId> <artifactId>velocity-engine-core</artifactId>
<version>2.0</version> <version>2.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>

View File

@ -28,7 +28,7 @@ public final class TakesApp {
new TkFallback( new TkFallback(
new TkSlf4j( new TkSlf4j(
new TkFork( new TkFork(
new FkRegex("/", "Hello, World!"), new FkRegex("/", new TakesHelloWorld()),
new FkRegex("/index", new TakesIndex()), new FkRegex("/index", new TakesIndex()),
new FkRegex("/contact", new TakesContact()), new FkRegex("/contact", new TakesContact()),
new FkRegex("/createUser", new TakesCreateUser(TakesApp.dbConnection())), new FkRegex("/createUser", new TakesCreateUser(TakesApp.dbConnection())),
@ -46,8 +46,7 @@ public final class TakesApp {
); );
} }
}) })
), ), 6060
6060
).start(Exit.NEVER); ).start(Exit.NEVER);
} }

View File

@ -1,8 +1,5 @@
package com.baeldung.takes; package com.baeldung.takes;
import java.io.IOException;
import java.sql.SQLException;
import org.takes.Request; import org.takes.Request;
import org.takes.Response; import org.takes.Response;
import org.takes.Take; import org.takes.Take;
@ -13,7 +10,7 @@ import org.takes.rs.RsWithType;
public final class TakesContact implements Take { public final class TakesContact implements Take {
@Override @Override
public Response act(Request req) throws IOException, SQLException { public Response act(Request req) {
return new RsWithStatus(new RsWithType(new RsWithBody("<html>" return new RsWithStatus(new RsWithType(new RsWithBody("<html>"
+ "<head>" + "<head>"
+ "<title>Takes Application - Contact</title></head>" + "<title>Takes Application - Contact</title></head>"
@ -22,5 +19,4 @@ public final class TakesContact implements Take {
+ "</body></html>"), "text/html"), 200); + "</body></html>"), "text/html"), 200);
} }
} }

View File

@ -21,7 +21,7 @@ public final class TakesCreateUser implements Take {
} }
@Override @Override
public Response act(final Request req) throws IOException, SQLException { public Response act(final Request req) throws IOException {
RqForm form = new RqFormSmart(req); RqForm form = new RqFormSmart(req);
Iterable<String> idParam = form.param("id"); Iterable<String> idParam = form.param("id");

View File

@ -5,7 +5,7 @@ import org.takes.Response;
import org.takes.Take; import org.takes.Take;
import org.takes.rs.RsText; import org.takes.rs.RsText;
public final class TkRoute implements Take { public class TakesHelloWorld implements Take {
@Override @Override
public Response act(final Request request) { public Response act(final Request request) {

View File

@ -1,7 +1,6 @@
package com.baeldung.takes; package com.baeldung.takes;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException;
import org.takes.Request; import org.takes.Request;
import org.takes.Response; import org.takes.Response;
@ -12,7 +11,7 @@ import org.takes.rs.RsVelocity;
public final class TakesIndex implements Take { public final class TakesIndex implements Take {
@Override @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"))); return new RsHtml(new RsVelocity(this.getClass().getResource("/templates/index.vm") ,new RsVelocity.Pair("userName", "Anshul")));
} }

View File

@ -26,7 +26,7 @@ public final class TakesReadUser implements Take {
} }
@Override @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(); Href href = new RqHref.Base(req).href();
Iterable<String> ids = href.param("id"); Iterable<String> ids = href.param("id");
int id = Integer.parseInt((String) ids.iterator().next()); int id = Integer.parseInt((String) ids.iterator().next());