* BAEL-1277: RESTFul CRUD application with JavaLite.

* BAEL-1277: RESTFul CRUD application with JavaLite. Adding exception handling.

* BAEL-1277: Changes after editors review.
This commit is contained in:
Magdalena Krause 2018-01-08 18:34:16 -03:00 committed by maibin
parent 727554bf47
commit cbd1a9dfbf
5 changed files with 79 additions and 86 deletions
java-lite
pom.xml
src/main/java/app/controllers

@ -7,6 +7,7 @@
<groupId>org.baeldung</groupId>
<artifactId>java-lite</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>com.baeldung</groupId>
@ -15,7 +16,7 @@
</parent>
<properties>
<jetty.maven.plugin.version>9.3.4.RC1</jetty.maven.plugin.version>
<jetty.maven.plugin.version>9.4.8.v20171121</jetty.maven.plugin.version>
<activejdbc.version>1.4.13</activejdbc.version>
<activeweb.version>1.15</activeweb.version>
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
@ -85,16 +86,6 @@
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-lgpl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

@ -10,6 +10,8 @@ import java.util.Map;
@RESTful
public class ProductsController extends AppController {
private ObjectMapper mapper = new ObjectMapper();
public void index() {
try {
view("products", Product.findAll());
@ -22,7 +24,7 @@ public class ProductsController extends AppController {
public void create() {
try {
Map payload = new ObjectMapper().readValue(getRequestString(), Map.class);
Map payload = mapper.readValue(getRequestString(), Map.class);
Product p = new Product();
p.fromMap(payload);
p.saveIt();
@ -36,7 +38,7 @@ public class ProductsController extends AppController {
public void update() {
try {
Map payload = new ObjectMapper().readValue(getRequestString(), Map.class);
Map payload = mapper.readValue(getRequestString(), Map.class);
String id = getId();
Product p = Product.findById(id);
if (p == null) {