Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_java2b_20250412
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
alx_java2b_20250412
Commits
2114d7ad
Commit
2114d7ad
authored
May 25, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
styl i spis treści
parent
5362c128
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
4 deletions
+151
-4
RootController.java
...Spring/src/main/java/org/example/demo/RootController.java
+35
-4
styl.css
PC35-Spring/src/main/resources/static/styl.css
+54
-0
index.html
PC35-Spring/src/main/resources/templates/index.html
+46
-0
ping.html
PC35-Spring/src/main/resources/templates/ping.html
+16
-0
No files found.
PC35-Spring/src/main/java/org/example/demo/RootController.java
View file @
2114d7ad
package
org
.
example
.
demo
;
package
org
.
example
.
demo
;
import
java.util.Map
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
jakarta.servlet.http.HttpServletRequest
;
/* Klasa typu Controller decyduje, w jaki sposób będą obsługiwane zapytania przychodzące na serwer.
* W projekcie może być wiele kontrolerów, a każdy kontroler może mieć wiele metod obsługujących zapytania.
*/
@Controller
@Controller
public
class
RootController
{
public
class
RootController
{
// @RequestMapping - obsługuje wszystkie typy zapytań (GET, POST, PUT, ...) pod podanym adresem
// @RequestMapping - obsługuje wszystkie typy zapytań (GET, POST, PUT, ...) pod podanym adresem
@RequestMapping
(
"/"
)
@RequestMapping
(
"/"
)
@ResponseBody
public
String
stronaGlowna
()
{
public
String
stronaGlowna
()
{
return
"
<h1>Witaj w Springu</h1><p>Lalala, to jest dalsza część</p>
"
;
return
"
index.html
"
;
}
}
// obsługa tylko zapytań typu GET
// obsługa tylko zapytań typu GET
...
@@ -25,5 +30,31 @@ public class RootController {
...
@@ -25,5 +30,31 @@ public class RootController {
public
String
hello
()
{
public
String
hello
()
{
return
"Hello world"
;
return
"Hello world"
;
}
}
@RequestMapping
(
"/ping"
)
public
String
ping
(
HttpServletRequest
request
,
Model
model
)
{
// Do metod w kontrolerze można dodawać parametry różnych typów,
// które "Spring zna" i gdy taki parametr się pojawia, to Spring
// wywołując metodę przekazuje nam w tym parametrze odpowiedni obiekt.
// To się nazywa wstrzykiwanie parametrów / parameter injection.
// A ogólnie to podejście, że nie my wywołuemy metodę, aby coś odczytać,
// tylko spring wywołuje NASZĄ metodę i Spring NAM przekazuje wymagane parametry,
// nazywa się "inversion of control" (IoC).
// Przykładowo tutaj dodaliśmy do metody parametr HttpServletRequest
// i Spring przekazuje nam tu techniczne informacje o zapytaniu (to samo, co
// było w serwletach).
// Do modelu można też dodać słownik / mapę.
// Odczyt wartości wygląda później np. tak ${clientInfo.userAgent}
String
ip
=
request
.
getRemoteAddr
();
String
host
=
request
.
getRemoteHost
();
System
.
out
.
println
(
"Zapytanie z adresu "
+
ip
);
model
.
addAttribute
(
"clientInfo"
,
Map
.
of
(
"userAgent"
,
request
.
getHeader
(
"User-Agent"
),
"ip"
,
ip
,
"host"
,
host
));
return
"ping.html"
;
}
}
}
PC35-Spring/src/main/resources/static/styl.css
0 → 100644
View file @
2114d7ad
body
{
background-color
:
#FFFFCC
;
font-family
:
'Arial'
,
sans-serif
;
}
h1
{
color
:
green
;
text-align
:
center
;
}
form
{
margin
:
30px
auto
;
padding
:
20px
;
width
:
800px
;
border
:
4px
solid
blue
;
background-color
:
#AAEEFF
;
}
.wynik
{
background-color
:
#FFFFFF
;
border
:
3px
solid
green
;
margin
:
20px
auto
;
width
:
800px
;
padding
:
10px
;
color
:
green
;
}
.error
{
background-color
:
#FFFFFF
;
border
:
6px
double
red
;
margin
:
20px
auto
;
padding
:
10px
;
width
:
800px
;
color
:
red
;
font-weight
:
bold
;
}
table
.tabela-walut
{
background-color
:
#FFFFFF
;
border-collapse
:
collapse
;
border
:
3px
solid
black
;
margin
:
0
auto
;
}
table
.tabela-walut
td
,
table
.tabela-walut
th
{
border
:
1px
solid
black
;
padding
:
2px
;
}
table
.tabela-walut
th
{
background-color
:
#FFCCDD
;
border-bottom
:
3px
double
black
;
}
PC35-Spring/src/main/resources/templates/index.html
0 → 100644
View file @
2114d7ad
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
lang=
"pl"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Aplikacja springowa - spis treści
</title>
<link
rel=
"stylesheet"
type=
"text/css"
th:href=
"@{/styl.css}"
>
</head>
<body>
<h1>
Aplikacja springowa - Spis treści
</h1>
<h2>
Przykłady pisane bezpośrednio w Controllerze
</h2>
<ul>
<li><a
th:href=
"@{/hello}"
>
Hello
</a></li>
<li><a
th:href=
"@{/ping}"
>
Ping
</a></li>
<!-- <li><a th:href="@{/czas}">Czas - zadanie na lekcji</a></li> -->
<li><a
th:href=
"@{/time1}"
>
Czas obiektowo
</a>
(json)
</li>
<li><a
th:href=
"@{/time2}"
>
Czas tekstowo
</a></li>
<li><a
th:href=
"@{/time3}"
>
Czas tekstowo
</a>
(text/plain)
</li>
<li><a
th:href=
"@{/time4}"
>
Czas HTML w Javie
</a></li>
</ul>
<h2>
Przykłady z szablonami
</h2>
<ul>
<li><a
th:href=
"@{/time5}"
>
Czas szablon prosty
</a></li>
<li><a
th:href=
"@{/time6}"
>
Czas szablon rozbudowany
</a></li>
</ul>
<h2>
Przykład Parametry
</h2>
<ul>
<li><a
th:href=
"@{/parametry/witaj}"
>
witaj
</a></li>
<li><a
th:href=
"@{/parametry/witaj(imie='Ala')}"
>
witaj?imie=Ala
</a></li>
<li><a
th:href=
"@{/parametry/powtorz}"
>
powtorz
</a></li>
<li><a
th:href=
"@{/parametry/powtorz(tekst='Ola ma psa')}"
>
powtorz
</a>
n = 1
</li>
<li><a
th:href=
"@{/parametry/powtorz(tekst='Ala ma kota',n=10)}"
>
powtorz
</a>
n = 10
</li>
<li><a
th:href=
"@{/parametry/techniczne}"
>
parametry techniczne
</a></li>
</ul>
<h2>
Formularze
</h2>
<ul>
<li><a
th:href=
"@{/rozmowa}"
>
Rozmowa
</a></li>
<li><a
th:href=
"@{/kalkulator}"
>
Kalkulator
</a></li>
</ul>
</body>
</html>
PC35-Spring/src/main/resources/templates/ping.html
0 → 100644
View file @
2114d7ad
<!DOCTYPE html>
<html
lang=
"pl"
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Ping
</title>
<link
rel=
"stylesheet"
type=
"text/css"
th:href=
"@{/styl.css}"
href=
"../static/styl.css"
>
</head>
<body>
<h2>
Informacje o kliencie
</h2>
<ul>
<li>
Adres:
<strong
th:text=
"${clientInfo.ip}"
>
1.2.3.4
</strong>
(
<span
th:text=
"${clientInfo.host}"
>
abc.com
</span>
)
</li>
<li>
Przeglądarka:
<strong
th:text=
"${clientInfo.userAgent}"
>
IE
</strong></li>
</ul>
</body>
</html>
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