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
0f34b3fc
Commit
0f34b3fc
authored
May 11, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TimeResource - dt jako pole i wyjaśnienie polityki "per request"
parent
7157b557
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
+28
-5
TimeResource.java
PC26-RestSerwer/src/main/java/rest/TimeResource.java
+28
-5
No files found.
PC26-RestSerwer/src/main/java/rest/TimeResource.java
View file @
0f34b3fc
...
...
@@ -10,40 +10,63 @@ import jakarta.ws.rs.Produces;
@Path
(
"/dt"
)
@Produces
(
"text/plain;charset=UTF-8"
)
// @Singleton
public
class
TimeResource
{
// W JAX-RS domyślne zachowanie jest takie, że dla każdego requestu tworzony jest nowy obiekt klasy obsługującej zapytania.
// (polityka "per request"; można ją zmienić za pomocą adnotacji @Singleton - wtedy jeden obiekt obsłuży wszystkie zapytania)
// Daje to możliwość zapisania pewnych ulotnych informacji w polach prywatnych tej klasy - nikt nam ich nie nadpisze.
private
LocalDateTime
dt
=
LocalDateTime
.
now
();
{
System
.
out
.
println
(
"Powstaje obiekt TimeResource z odczytanym czasem "
+
dt
);
}
// ta metoda obsługuje adres .../dt
@GET
public
LocalDateTime
odczytajDataICzas
()
{
return
LocalDateTime
.
now
()
;
return
dt
;
}
// ta metoda obsługuje adres .../dt/date
@GET
@Path
(
"/date"
)
public
LocalDate
odczytajDate
()
{
return
LocalDate
.
now
();
return
dt
.
toLocalDate
();
}
// ta metoda obsługuje adres .../dt/date/year
@GET
@Path
(
"/date/year"
)
public
int
odczytajRok
()
{
return
odczytajDate
().
getYear
();
return
dt
.
getYear
();
}
// ta metoda obsługuje adres .../dt/date/month
@GET
@Path
(
"/date/month"
)
public
int
odczytajMiesiac
()
{
return
dt
.
getMonthValue
();
}
// ta metoda obsługuje adres .../dt/date/day
@GET
@Path
(
"/date/day"
)
public
int
odczytajDzien
()
{
return
dt
.
getDayOfMonth
();
}
// ta metoda obsługuje adres .../dt/time
@GET
@Path
(
"/time"
)
public
LocalTime
odczytajCzas
()
{
return
LocalTime
.
now
();
return
dt
.
toLocalTime
();
}
// ta metoda obsługuje adres .../dt/time/second
@GET
@Path
(
"/time/second"
)
public
int
odczytajSekunde
()
{
return
odczytajCzas
()
.
getSecond
();
return
dt
.
getSecond
();
}
}
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