Last active
December 1, 2019 19:28
-
-
Save mloza/4032b3c21dc7d73ee73d26cdb7eb65b5 to your computer and use it in GitHub Desktop.
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
INSERT INTO task(name, description, budget, done) VALUES('Task 1', 'Description of task 1', 100.00, 1); | |
INSERT INTO task(name, description, budget, done) VALUES('Task 2', 'Description of task 2 Do', 100.00, 1); | |
INSERT INTO task(name, description, budget, done) VALUES('Task 3', 'Description of task 3 Do', 50.00, 0); |
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
<dependency> | |
<groupId>com.h2database</groupId> | |
<artifactId>h2</artifactId> | |
</dependency> |
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
Hibernate: drop table task if exists | |
Hibernate: create table task (id bigint generated by default as identity, budget double, description clob, done boolean, name varchar(255), primary key (id)) |
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
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-jpa</artifactId> | |
</dependency> |
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
@EnableAutoConfiguration | |
@ComponentScan | |
@EnableJpaRepositories(basePackageClasses = TaskRepository.class) | |
public class Main { | |
public static void main(String[] args) { | |
SpringApplication.run(Main.class, args); | |
} | |
} |
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
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<version>5.1.34</version> | |
</dependency> |
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
spring.datasource.url=jdbc:mysql://localhost/nazwa-bazy | |
spring.datasource.username=login | |
spring.datasource.password=haslo | |
spring.datasource.driver-class-name=com.mysql.jdbc.Driver |
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
spring.jpa.show-sql = true |
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
. |
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
TaskEntity{id=1, name='Task 1', description='Test task', budget=123.55, done=true} | |
TaskEntity{id=2, name='Task 1', description='Test task', budget=123.55, done=true} | |
TaskEntity{id=3, name='Task 1', description='Test task', budget=123.55, done=true} | |
TaskEntity{id=4, name='Task 1', description='Test task', budget=123.55, done=true} | |
TaskEntity{id=5, name='Task 1', description='Test task', budget=123.55, done=true} | |
TaskEntity{id=6, name='Task 1', description='Test task', budget=123.55, done=true} |
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
TaskEntity{id=1, name='Task 1', description='Description of task 1', budget=100.0, done=true} | |
TaskEntity{id=2, name='Task 2', description='Description of task 2 Do', budget=100.0, done=true} | |
TaskEntity{id=3, name='Task 3', description='Description of task 3 Do', budget=50.0, done=false} | |
TaskEntity{id=4, name='Task 1', description='Test task', budget=123.55, done=true} |
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
Tasks with done set to true: | |
TaskEntity{id=1, name='Task 1', description='Description of task 1', budget=100.0, done=true} | |
TaskEntity{id=2, name='Task 2', description='Description of task 2 Do', budget=100.0, done=true} | |
Tasks with done set to false: | |
TaskEntity{id=3, name='Task 3', description='Description of task 3 Do', budget=50.0, done=false} | |
Tasks with "Do" in description: | |
TaskEntity{id=2, name='Task 2', description='Description of task 2 Do', budget=100.0, done=true} | |
TaskEntity{id=3, name='Task 3', description='Description of task 3 Do', budget=50.0, done=false} |
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
@Entity | |
public class Task { | |
@GeneratedValue | |
@Id | |
private Long id; | |
@Column | |
private String name; | |
@Column | |
@Lob | |
private String description; | |
@Column | |
private Double budget; | |
@Column | |
private Boolean done; | |
//Gettery, Settery itp. | |
} |
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
public interface TaskRepository extends CrudRepository<Task, Long> { } |
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
public interface TaskRepository extends CrudRepository<task, long> { | |
public List findByDone(Boolean done); | |
@Query("select t from Task t where t.description like %?1%") | |
public List getByDescriptionLike(String search); | |
} |
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
@Autowired | |
public TaskRepository taskRepository; |
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
@RequestMapping("/db") | |
@ResponseBody | |
public String testMethod() { | |
StringBuilder response = new StringBuilder(); | |
Task task = new Task() | |
.withName("Task 1") | |
.withDescription("Test task") | |
.withBudget(123.55) | |
.withDone(true); | |
taskRepository.save(task); | |
for(Task i: taskRepository.findAll()) { | |
response.append(i).append("<br>"); | |
} | |
return response.toString(); | |
} |
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
@RequestMapping("/db2") | |
@ResponseBody | |
public String testMethod2() { | |
StringBuilder response = new StringBuilder(); | |
response.append("Tasks with done set to true:\n"); | |
for(Task i: taskRepository.findByDone(true)) { | |
response.append(i).append("\n"); | |
} | |
response.append("Tasks with done set to false:\n"); | |
for(Task i: taskRepository.findByDone(false)) { | |
response.append(i).append("\n"); | |
} | |
response.append("Tasks with \"Do\" in description:\n"); | |
for(Task i: taskRepository.getByDescriptionLike("Do")) { | |
response.append(i).append("\n"); | |
} | |
return response.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment