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
@RestController | |
public class HelloController { | |
@GetMapping(value = { "/" }) | |
public String index() { | |
return "Hello world"; | |
} | |
} |
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
import lombok.Data; | |
import javax.persistence.Entity; | |
import javax.persistence.Table; | |
import javax.persistence.*; | |
@Data | |
@Table(name = "todos") | |
@Entity |
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
# H2 console | |
spring.h2.console.enabled = true | |
spring.h2.console.path = /h2 | |
# Datasource | |
spring.datasource.url = jdbc:h2:file:~/todos | |
spring.datasource.username = sa | |
spring.datasource.password = | |
spring.datasource.driver-class-name = org.h2.Driver | |
spring.jpa.show-sql = true |
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
import com.manjula.todo.model.Todo; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
public interface TodoRepository extends JpaRepository<Todo, Long> { | |
} |
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
import lombok.Data; | |
@Data | |
public class TodoDto { | |
private Long id; | |
private String title; | |
private String summary; | |
} |
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
public TodoDto view() { | |
TodoDto dto = new TodoDto(); | |
BeanUtils.copyProperties(this, dto); | |
return dto; | |
} | |
public static Todo valueOf(TodoDto dto) { | |
Todo todo = new Todo(); | |
BeanUtils.copyProperties(dto, todo); | |
return todo; |
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
import com.manjula.todo.dto.TodoDto; | |
import java.util.List; | |
public interface TodoService { | |
Long save(TodoDto todoDto); | |
TodoDto findById(Long id); |
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
import com.manjula.todo.dto.TodoDto; | |
import com.manjula.todo.model.Todo; | |
import com.manjula.todo.repository.TodoRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
@Service |
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
@RestController | |
@RequestMapping("/todos") | |
public class TodoController { | |
@Autowired | |
private TodoService todoService; | |
@GetMapping | |
public ResponseEntity<?> getAll() { | |
// list all |
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
@RestController | |
@RequestMapping("/todos") | |
public class TodoController { | |
@Autowired | |
private TodoService todoService; | |
@GetMapping | |
public ResponseEntity<?> getAll() { | |
List<TodoDto> todos = todoService.findAll(); |
OlderNewer