new foo controller - work in progress

This commit is contained in:
eugenp
2014-01-10 11:50:41 +02:00
parent f06b24bea2
commit 71c8dffe40
4 changed files with 111 additions and 12 deletions
@@ -0,0 +1,28 @@
package org.baeldung.web.controller;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
import org.baeldung.web.dto.Foo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class FooController {
public FooController() {
super();
}
// API
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}")
public @ResponseBody
Foo findById(@PathVariable final long id) {
return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4));
}
}
@@ -0,0 +1,39 @@
package org.baeldung.web.dto;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("Foo")
public class Foo {
private long id;
private String name;
public Foo() {
super();
}
public Foo(final long id, final String name) {
super();
this.id = id;
this.name = name;
}
// API
public long getId() {
return id;
}
public void setId(final long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
}