Skip to content

Instantly share code, notes, and snippets.

@sivaprasadreddy
Created September 4, 2014 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivaprasadreddy/26d2e24ab9b1bde8e51d to your computer and use it in GitHub Desktop.
Save sivaprasadreddy/26d2e24ab9b1bde8e51d to your computer and use it in GitHub Desktop.
Todo Entity-Repo-Ctrl.java classes
package com.sivalabs.app.entities;
@Entity
public class Todo {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String description;
@Temporal(TemporalType.TIMESTAMP)
private Date createdOn = new Date();
//setters and getters
}
package com.sivalabs.app.repos;
public interface TodoRepository extends JpaRepository<Todo, Integer>{
}
package com.sivalabs.app.controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.sivalabs.app.entities.Todo;
import com.sivalabs.app.repos.TodoRepository;
@RestController
@RequestMapping("/todos")
public class TodoController {
@Autowired
private TodoRepository todoRepository;
@RequestMapping(value="", method=RequestMethod.GET)
public List<Todo> persons() {
return todoRepository.findAll();
}
@RequestMapping(value="", method=RequestMethod.POST)
public Todo create(@RequestBody Todo todo) {
return todoRepository.save(todo);
}
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
public void delete(@PathVariable("id") Integer id) {
todoRepository.delete(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment