Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-jpa</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- @Entity
- @Table(name = "greetings")
- public class Greeting {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "greeting_id")
- private long id;
- @Column(name = "text")
- private String text;
- // getters and setters here
- }
- @Repository
- public interface GreetingRepository extends JpaRepository<Greeting, Long> {
- }
- @RestController("/hello")
- public class GreetingsController {
- @Autowired
- private GreetingRepository repo;
- @RequestMapping(method = RequestMethod.GET)
- public Collection<Greeting> getGreetings() {
- return repo.findAll();
- }
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- public Greeting getGreeting(@PathVariable long id) {
- return repo.findOne(id);
- }
- }
- spring.jpa.hibernate.ddl-auto=create-drop
- spring.jpa.properties.hibernate.globally_quoted_identifiers=true
- spring.datasource.url=jdbc:mysql://localhost/example
- spring.datasource.username=root
- spring.datasource.password=secret
- spring.datasource.driverClassName=com.mysql.jdbc.Driver
- mysql> describe greetings;
- +-------------+--------------+------+-----+---------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +-------------+--------------+------+-----+---------+----------------+
- | greeting_id | bigint(20) | NO | PRI | NULL | auto_increment |
- | text | varchar(255) | YES | | NULL | |
- +-------------+--------------+------+-----+---------+----------------+
- 2 rows in set (0.00 sec)
- Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: "hello"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement