Skip to content

Commit 004ca04

Browse files
committed
Spring Boot Employee MVC DB UPDATE
1 parent 92a6624 commit 004ca04

File tree

27 files changed

+1295
-16
lines changed

27 files changed

+1295
-16
lines changed

Part-5 Spring Boot Web Application/SpringMVC+DB/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
<artifactId>mysql-connector-java</artifactId>
4040
<scope>runtime</scope>
4141
</dependency>
42+
43+
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
44+
<dependency>
45+
<groupId>org.thymeleaf</groupId>
46+
<artifactId>thymeleaf</artifactId>
47+
<version>3.0.11.RELEASE</version>
48+
</dependency>
49+
4250
<dependency>
4351
<groupId>org.springframework.boot</groupId>
4452
<artifactId>spring-boot-starter-test</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package spring.mvc.controller;
22

3+
import com.fasterxml.jackson.databind.util.ViewMatcher;
34
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.stereotype.Controller;
56
import org.springframework.ui.Model;
6-
import org.springframework.web.bind.annotation.GetMapping;
7-
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.*;
88
import spring.mvc.repository.CompanyRepository;
99

1010
/**
1111
* @Created 27 / 03 / 2020 - 12:19 PM
1212
* @project SpringMVC
1313
* @Author Hamdamboy
1414
*/
15-
@Controller
15+
@RestController
1616
public class ControllerCompany {
1717
//
1818
@Autowired
@@ -23,9 +23,11 @@ public String again(){
2323
// model.addAttribute("company", companyRepository.findAll());
2424
return "working";
2525
}
26-
@RequestMapping("/")
27-
public String home(Model model){
28-
model.addAttribute("company", companyRepository.findAll());
29-
return "index";
26+
27+
@RequestMapping(value = "/to", method = RequestMethod.GET)
28+
public String home(@PathVariable int id, Model model){
29+
model.addAttribute("index", companyRepository.findById(id));
30+
return "redirect:/index";
31+
3032
}
3133
}

Part-5 Spring Boot Web Application/SpringMVC+DB/src/main/java/spring/mvc/repository/CompanyRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
* @Author Hamdamboy
1010
*/
1111
public interface CompanyRepository extends JpaRepository<Company, Integer> {
12+
13+
1214
}

Part-5 Spring Boot Web Application/SpringMVC+DB/src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ logging.level.org.springframework=INFO
77
################### Data Configuration #########################
88

99
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
10-
spring.datasource.url=jdbc:mysql://localhost:3306/management
10+
spring.datasource.url=jdbc:mysql://localhost:3306/management?serverTimezone=UTC
1111
spring.datasource.username=root
1212
spring.datasource.password=posilka2020
1313

1414
############################Hibernate Configuration ################
1515

16-
spring.jpa.hibernate.ddl-auto=create
16+
spring.jpa.hibernate.ddl-auto=update
1717
spring.jpa.show-sql=true
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
3+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4+
<html lang="en">
5+
<head>
6+
7+
<link rel="stylesheet" type="text/css"
8+
href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
9+
<c:url value="/css/main.css" var="jstlCss" />
10+
<link href="${jstlCss}" rel="stylesheet" />
11+
12+
</head>
13+
<body>
14+
<div class="container">
15+
<header>
16+
<h1>Spring MVC + JSP + JPA + Spring Boot 2</h1>
17+
</header>
18+
<div class="starter-template">
19+
<h1>Users List</h1>
20+
<table
21+
class="table table-striped table-hover table-condenstemplatesed table-bordered">
22+
<tr>
23+
<th>Id</th>
24+
<th>Name</th>
25+
</tr>
26+
<c:forEach var="user" items="${users}">
27+
<tr>
28+
<td>${user.id}</td>
29+
<td>${user.name}</td>
30+
</tr>
31+
</c:forEach>
32+
</table>
33+
</div>
34+
35+
</div>
36+
37+
<script type="text/javascript"
38+
src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
39+
</body>
40+
41+
</html>

Part-5 Spring Boot Web Application/SpringMVC+DB/src/main/webapp/WEB-INF/jsp/index.jsp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
<h1>Spring MVC + JSP + JPA + Spring Boot 2</h1>
1717
</header>
1818
<div class="starter-template">
19-
<h1>Users List</h1>
19+
<h1>Company List</h1>
2020
<table
21-
class="table table-striped table-hover table-condensed table-bordered">
21+
class="table table-striped table-hover table-condenstemplatesed table-bordered">
2222
<tr>
2323
<th>Id</th>
2424
<th>Name</th>
2525
</tr>
26-
<c:forEach var="user" items="${users}">
26+
<c:forEach var="company" items="${company}">
2727
<tr>
28-
<td>${user.id}</td>
29-
<td>${user.name}</td>
28+
<td>${company.id}</td>
29+
<td>${company.name}</td>
3030
</tr>
3131
</c:forEach>
3232
</table>

Part-8 Spring Boot Real Projects/3.TodoProjectDB/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@
6464
<artifactId>lombok</artifactId>
6565
<version>1.18.12</version>
6666
</dependency>
67+
68+
<dependency>
69+
<groupId>mysql</groupId>
70+
<artifactId>mysql-connector-java</artifactId>
71+
<scope>runtime</scope>
72+
</dependency>
73+
74+
6775
</dependencies>
6876

6977
<build>

Part-8 Spring Boot Real Projects/3.TodoProjectDB/src/main/java/spring/project/entity/Todo.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* @Project is SpringSimpleTodo
1313
*/
1414
@Entity
15-
@Table(name = "todos")
15+
@Table(name = "schedule")
1616
@Data
1717
//@NoArgsConstructor
18-
//@AllArgsConstructor
18+
//@AllArgsConstructorf
1919
public class ToDo {
2020

2121
@Id
@@ -53,4 +53,8 @@ public ToDo(String todoItem, String completed){
5353
this.todoItem = todoItem;
5454
this.completed = completed;
5555
}
56+
57+
public ToDo(long id) {
58+
this.id = id;
59+
}
5660
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package spring.project.repository;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.data.domain.Example;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.domain.Sort;
8+
import spring.project.entity.ToDo;
9+
10+
import java.util.List;
11+
import java.util.Optional;
12+
13+
/**
14+
* @Author: apple
15+
* @created on 02/05/2020
16+
* @Project is TodoProjectDB
17+
*/
18+
public class LogicRepository implements ToDoRepository{
19+
20+
21+
@Override
22+
public List<ToDo> findAll() {
23+
return null;
24+
}
25+
26+
@Override
27+
public List<ToDo> findAll(Sort sort) {
28+
return null;
29+
}
30+
31+
@Override
32+
public Page<ToDo> findAll(Pageable pageable) {
33+
return null;
34+
}
35+
36+
37+
@Override
38+
public List<ToDo> findAllById(Iterable<Long> iterable) {
39+
return null;
40+
}
41+
42+
@Override
43+
public long count() {
44+
return 0;
45+
}
46+
47+
@Override
48+
public void deleteById(Long aLong) {
49+
50+
}
51+
52+
@Override
53+
public void delete(ToDo toDo) {
54+
55+
}
56+
57+
@Override
58+
public void deleteAll(Iterable<? extends ToDo> iterable) {
59+
60+
}
61+
62+
@Override
63+
public void deleteAll() {
64+
65+
}
66+
67+
@Override
68+
public <S extends ToDo> S save(S s) {
69+
return null;
70+
}
71+
72+
@Override
73+
public <S extends ToDo> List<S> saveAll(Iterable<S> iterable) {
74+
return null;
75+
}
76+
77+
@Override
78+
public Optional<ToDo> findById(Long aLong) {
79+
return Optional.empty();
80+
}
81+
82+
@Override
83+
public boolean existsById(Long aLong) {
84+
return false;
85+
}
86+
87+
@Override
88+
public void flush() {
89+
90+
}
91+
92+
@Override
93+
public <S extends ToDo> S saveAndFlush(S s) {
94+
return null;
95+
}
96+
97+
@Override
98+
public void deleteInBatch(Iterable<ToDo> iterable) {
99+
100+
}
101+
102+
@Override
103+
public void deleteAllInBatch() {
104+
105+
}
106+
107+
@Override
108+
public ToDo getOne(Long aLong) {
109+
return null;
110+
}
111+
112+
@Override
113+
public <S extends ToDo> Optional<S> findOne(Example<S> example) {
114+
return Optional.empty();
115+
}
116+
117+
@Override
118+
public <S extends ToDo> List<S> findAll(Example<S> example) {
119+
return null;
120+
}
121+
122+
@Override
123+
public <S extends ToDo> List<S> findAll(Example<S> example, Sort sort) {
124+
return null;
125+
}
126+
127+
@Override
128+
public <S extends ToDo> Page<S> findAll(Example<S> example, Pageable pageable) {
129+
return null;
130+
}
131+
132+
@Override
133+
public <S extends ToDo> long count(Example<S> example) {
134+
return 0;
135+
}
136+
137+
@Override
138+
public <S extends ToDo> boolean exists(Example<S> example) {
139+
return false;
140+
}
141+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11

2+
# DB configuration
3+
4+
################ JSP ####################
5+
#spring.mvc.view.suffix=/WEB-INF/jsp/
6+
#spring.mvc.view.prefix=.jsp
7+
#
8+
#logging.level.org.springframework=INFO
9+
10+
################### Data Configuration #########################
11+
12+
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
13+
spring.datasource.url=jdbc:mysql://localhost:3306/worlds
14+
spring.datasource.username=root
15+
spring.datasource.password=posilka2020
16+
17+
############################Hibernate Configuration ################
18+
19+
spring.jpa.hibernate.ddl-auto=create
20+
spring.jpa.show-sql=true
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/

0 commit comments

Comments
 (0)