Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
javab_20230928
Commits
cb853633
Commit
cb853633
authored
Oct 19, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BlogService i dependency injection
parent
f68d8e1c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
6 deletions
+46
-6
BlogController.java
...Spring/src/main/java/com/example/demo/BlogController.java
+5
-6
BlogRestController.java
...ng/src/main/java/com/example/demo/BlogRestController.java
+21
-0
BlogService.java
PC26-Spring/src/main/java/com/example/demo/BlogService.java
+20
-0
No files found.
PC26-Spring/src/main/java/com/example/demo/BlogController.java
View file @
cb853633
package
com
.
example
.
demo
;
package
com
.
example
.
demo
;
import
java.util.ArrayList
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.List
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
@@ -12,7 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -12,7 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@Controller
@RequestMapping
(
"/blog"
)
@RequestMapping
(
"/blog"
)
public
class
BlogController
{
public
class
BlogController
{
private
List
<
String
>
teksty
=
new
ArrayList
<>();
@Autowired
private
BlogService
blogService
;
@GetMapping
@GetMapping
public
String
rozmowaGet
()
{
public
String
rozmowaGet
()
{
...
@@ -22,9 +21,9 @@ public class BlogController {
...
@@ -22,9 +21,9 @@ public class BlogController {
@PostMapping
@PostMapping
public
String
rozmowaPost
(
String
tekst
,
Model
model
)
{
public
String
rozmowaPost
(
String
tekst
,
Model
model
)
{
if
(
tekst
!=
null
&&
!
tekst
.
isBlank
())
{
if
(
tekst
!=
null
&&
!
tekst
.
isBlank
())
{
teksty
.
add
(
tekst
);
blogService
.
addTekst
(
tekst
);
}
}
model
.
addAttribute
(
"teksty"
,
teksty
);
model
.
addAttribute
(
"teksty"
,
blogService
.
getTeksty
()
);
return
"blog.html"
;
return
"blog.html"
;
}
}
...
...
PC26-Spring/src/main/java/com/example/demo/BlogRestController.java
0 → 100644
View file @
cb853633
package
com
.
example
.
demo
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
"/blog.json"
)
public
class
BlogRestController
{
@Autowired
private
BlogService
blogService
;
@GetMapping
public
List
<
String
>
getTeksty
()
{
return
blogService
.
getTeksty
();
}
}
PC26-Spring/src/main/java/com/example/demo/BlogService.java
0 → 100644
View file @
cb853633
package
com
.
example
.
demo
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
org.springframework.stereotype.Component
;
@Component
public
class
BlogService
{
private
List
<
String
>
teksty
=
Collections
.
synchronizedList
(
new
ArrayList
<>());
public
List
<
String
>
getTeksty
()
{
return
Collections
.
unmodifiableList
(
teksty
);
}
public
void
addTekst
(
String
tekst
)
{
teksty
.
add
(
tekst
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment