Skip to content

Commit

Permalink
Add Post representation using JPA
Browse files Browse the repository at this point in the history
JPA Entities are POJOs associated to data that can be persisted to
database. `Post` Entity represents a table of posts in the DB. Therefore
an instance of a `Post` can be used to manage a row in this table.

PostRepository it's an interface that extends JPARepository. By doing that, it
inherits different methods that can be used for common persistence operations.
  • Loading branch information
lidimayra committed Feb 7, 2020
1 parent e62c474 commit e755e5a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions myapp/src/main/java/com/example/myapp/Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.myapp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Post {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String content;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}
}
6 changes: 6 additions & 0 deletions myapp/src/main/java/com/example/myapp/PostRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.myapp;

import org.springframework.data.jpa.repository.JpaRepository;

public interface PostRepository extends JpaRepository<Post, Long> {
}

0 comments on commit e755e5a

Please sign in to comment.