Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ public Integer getId() {
return id;
}

public void setId(Integer id) {
public void setId(final Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
public void setName(final String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
public void setEmail(final String email) {
this.email = email;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete

public interface UserRepository extends CrudRepository<User, Long> {}
public interface UserRepository extends CrudRepository<User, Integer> {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
import org.springframework.web.bind.annotation.ResponseBody;

@Controller // This means that this class is a Controller
@RequestMapping(path = "/demo") // This means URL's start with /demo (after Application path)
public class MySQLResource {
@RequestMapping(path = "/user") // This means URL's start with /demo (after Application path)
public class DBResource {

@Autowired // This means to get the bean called userRepository
// Which is auto-generated by Spring, we will use it to handle the data
private UserRepository userRepository;

@GetMapping(path = "/add") // Map ONLY GET Requests
public @ResponseBody String addNewUser(@RequestParam String name, @RequestParam String email) {
public @ResponseBody String addNewUser(
@RequestParam final String name, @RequestParam final String email) {
// @ResponseBody means the returned String is the response, not a view name
// @RequestParam means it is a parameter from the GET or POST request

User n = new User();
final User n = new User();
n.setName(name);
n.setEmail(email);
userRepository.save(n);
Expand All @@ -34,4 +35,10 @@ public class MySQLResource {
// This returns a JSON or XML with the users
return userRepository.findAll();
}

@GetMapping(path = "/get")
public @ResponseBody User getUser(@RequestParam final int id) {
// This returns a JSON or XML with the users
return userRepository.findOne(id);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.datadoghq.examples.resources;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/")
public class HomeResource {

@RequestMapping(method = RequestMethod.GET)
public String test() {

final StringBuilder template = new StringBuilder();

template.append("Demo links");
template.append("<ul>");
template.append("<li><a href=\"/user/add?name=name&email=f@example.com\">Add a user</a></li>");
template.append("<li><a href=\"/user/all\">List all users</a></li>");
template.append("<li><a href=\"/user/get?id=1\">Get user with id=1</a></li>");
template.append("</ul>");

return template.toString();
}
}