Created
September 4, 2014 12:51
-
-
Save sivaprasadreddy/26d2e24ab9b1bde8e51d to your computer and use it in GitHub Desktop.
Todo Entity-Repo-Ctrl.java classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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