Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring Bootを触ってみた

2,049 views

Published on

社内勉強会にてSpring Bootについて発表した資料です。

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Spring Bootを触ってみた

  1. 1. Spring Boot 2016-12-22 onozaty
  2. 2. Spring Boot • • Play Framework • Spring • Play Scala Scala
  3. 3. Spring Boot • Spring Framework • Spring Framework
  4. 4. • Tomcat Jetty jar(Uber JAR) • Maven Gradle • 
 ( )
  5. 5. Spring Initializr • Spring Boot WEB
  6. 6. Spring Initializr • Project ( Maven Gradle ) • STS(Spring Tool Suite)
  7. 7. Spring Initializr • • http://start.spring.io/
  8. 8. Spring Initializr
  9. 9. Spring Initializr
  10. 10. Spring Initializr
  11. 11. Spring Initializr • •
  12. 12. Hello World! Dependencies Web Project
  13. 13. Hello World! Eclipse “Hello World!!” package com.example; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HelloController { @RequestMapping("/") @ResponseBody public String hello(){ return "Hello World!!"; } }
  14. 14. Hello World! Tomcat
  15. 15. • Spring Boot Spring • Web Spring MVC •
  16. 16. • Spring Boot • • • 
 https://github.com/spring-projects/spring-boot/tree/ master/spring-boot-samples
  17. 17. AutoConfigure • Spring Boot AutoConfigure • AutoConfigure
  18. 18. AutoConfigure • Flyway Flyway • H2 datasource H2 DB
  19. 19. DB • • Spring JDBC • Spring DATA JPA • MyBatis Spring
  20. 20. Spring JDBC • spring-boot-starter-jdbc • JDBC (Apache commons DbUtils )
  21. 21. Spring JDBC @Repository public class CustomerRepository { @Autowired private NamedParameterJdbcTemplate jdbcTemplate; public List<Customer> findAll() { return jdbcTemplate.query( "SELECT * FROM customers ORDER BY id", new BeanPropertyRowMapper<Customer>(Customer.class)); } public void update(Customer customer) { jdbcTemplate.update( "UPDATE customers SET name = :name, address = :address WHERE id = :id", new BeanPropertySqlParameterSource(customer)); } }
  22. 22. Spring DATA JPA • spring-boot-starter-data-jpa • JPA • JPA EntityManager Interface
  23. 23. Spring DATA JPA @Entity @Table(name = "customers") @Data @AllArgsConstructor @NoArgsConstructor public class Customer { @Id @GeneratedValue private Integer id; private String name; private String address; }
  24. 24. Spring DATA JPA @Service public class CustomerService { @Autowired private CustomerRepository customerRepository; public List<Customer> findAll() { return customerRepository.findAll(); } public List<Customer> findByName(String name) { return customerRepository.findByName(name); } public Customer create(Customer customer) { return customerRepository.save(customer); } @Repository public interface CustomerRepository extends JpaRepository<Customer, Integer> { public List<Customer> findByName(String name); }
  25. 25. REST API • CRUD API • RDBMS H2 • Spring DATA JPA • Flyway DB • Swagger
  26. 26. • • https://github.com/onozaty/spring-boot-sandbox/tree/ master/spring-boot-demo-20161222
  27. 27. • Spring •

×