-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>cz.ssinfotech.pridbros</groupId> | ||
<artifactId>blog</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.2.RELEASE</version> | ||
</parent> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-actuator</artifactId> | ||
</dependency> | ||
<!-- Runtime --> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
src/main/java/cz/ssinfotech/pridbros/blog/Application.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cz.ssinfotech.pridbros.blog; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.web.support.SpringBootServletInitializer; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
@EnableJpaRepositories | ||
@ComponentScan | ||
@SpringBootApplication | ||
public class Application extends SpringBootServletInitializer { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/cz/ssinfotech/pridbros/blog/HelloController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cz.ssinfotech.pridbros.blog; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import cz.ssinfotech.pridbros.blog.domain.Article; | ||
import cz.ssinfotech.pridbros.blog.repository.ArticleRepository; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
@Autowired | ||
ArticleRepository articleRepository; | ||
|
||
@RequestMapping("/create") | ||
public String create(@RequestParam("caption") String caption) { | ||
Article article = new Article(); | ||
article.setCaption(caption); | ||
articleRepository.save(article); | ||
return "Article was saved;"; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/cz/ssinfotech/pridbros/blog/domain/Article.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cz.ssinfotech.pridbros.blog.domain; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table | ||
public class Article { | ||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
private String caption; | ||
private String body; | ||
@ManyToOne | ||
private Author autor; | ||
|
||
public String getCaption() { | ||
return caption; | ||
} | ||
public void setCaption(String caption) { | ||
this.caption = caption; | ||
} | ||
public String getBody() { | ||
return body; | ||
} | ||
public void setBody(String body) { | ||
this.body = body; | ||
} | ||
public Author getAutor() { | ||
return autor; | ||
} | ||
public void setAutor(Author autor) { | ||
this.autor = autor; | ||
} | ||
public Integer getId() { | ||
return id; | ||
} | ||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/cz/ssinfotech/pridbros/blog/domain/Author.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cz.ssinfotech.pridbros.blog.domain; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table | ||
public class Author { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
private String name; | ||
private String email; | ||
@OneToMany | ||
private List<Article> articles; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public String getEmail() { | ||
return email; | ||
} | ||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
public List<Article> getArticles() { | ||
return articles; | ||
} | ||
public void setArticles(List<Article> articles) { | ||
this.articles = articles; | ||
} | ||
public Integer getId() { | ||
return id; | ||
} | ||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/cz/ssinfotech/pridbros/blog/repository/ArticleRepository.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cz.ssinfotech.pridbros.blog.repository; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import cz.ssinfotech.pridbros.blog.domain.Article; | ||
|
||
@Repository | ||
public interface ArticleRepository extends CrudRepository<Article, Integer>{ | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
server: | ||
port: 6080 | ||
spring: | ||
datasource: | ||
driver-class-name: org.h2.Driver | ||
url: jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE | ||
username: sa | ||
password: | ||
h2: | ||
console: | ||
enabled: true | ||
jpa: | ||
hibernate: | ||
ddl-auto: create |