Skip to content

Instantly share code, notes, and snippets.

View making's full-sized avatar

Toshiaki Maki making

View GitHub Profile
package com.example.domain;
import org.hibernate.validator.constraints.URL;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
package com.example.repository;
import com.example.domain.Bookmark;
import org.springframework.data.jpa.repository.JpaRepository;
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {
}
package com.example.service;
import com.example.domain.Bookmark;
import com.example.repository.BookmarkRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
package com.example.api;
import com.example.domain.Bookmark;
import com.example.service.BookmarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
package com.example.api;
import com.example.domain.Bookmark;
import com.example.service.BookmarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@EnableAutoConfiguration
@ComponentScan
public class App {
curl http://localhost:8080/api/bookmarks -v -X POST -H 'Content-Type:application/json' -d '{"name":"Google", "url":"http://google.com"}'
# Windowsの人は
curl http://localhost:8080/api/bookmarks -v -X POST -H "Content-Type:application/json" -d "{\"name\":\"Google\", \"url\":\"http://google.com\"}"
curl http://localhost:8080/api/bookmarks -v -X GET
curl http://localhost:8080/api/bookmarks/1 -v -X DELETE
spring:
datasource:
driverClassName: org.h2.Driver
url: jdbc:h2:file:/tmp/bookmark
username: sa
password:
jpa:
hibernate:
ddl-auto: update