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
0ab9fd36
Commit
0ab9fd36
authored
Jun 01, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
przykłady bez bazy danych - poprawki
parent
9b346521
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
25 deletions
+37
-25
DataCzas.java
PC38-SpringJersey/src/main/java/sklep/rest/DataCzas.java
+34
-22
JerseyConfig.java
PC38-SpringJersey/src/main/java/sklep/rest/JerseyConfig.java
+3
-3
No files found.
PC38-SpringJersey/src/main/java/sklep/rest/DataCzas.java
View file @
0ab9fd36
package
sklep
.
rest
;
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.Path
;
import
jakarta.ws.rs.Produces
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
@Path
(
"/now"
)
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.Path
;
@Path
(
"/dt"
)
// @Singleton
public
class
DataCzas
{
// 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
now
=
LocalDateTime
.
now
();
private
LocalDateTime
dt
=
LocalDateTime
.
now
();
{
// ten blok wykona się podczas tworzenia każdego obiektu
System
.
out
.
println
(
"Powstał obiekt DataCzas z czasem równym "
+
now
);
System
.
out
.
println
(
"Powstaje obiekt TimeResource z odczytanym czasem "
+
dt
);
}
// ta metoda obsługuje adres .../
api/now
// ta metoda obsługuje adres .../
dt
@GET
public
LocalDateTime
odczytajDataICzas
()
{
return
now
;
return
dt
;
}
// ta metoda obsługuje adres .../
api/now
/date
// ta metoda obsługuje adres .../
dt
/date
@GET
@Path
(
"/date"
)
public
LocalDate
odczytajDate
()
{
return
now
.
toLocalDate
();
return
dt
.
toLocalDate
();
}
// ta metoda obsługuje adres .../
api/now
/date/year
// ta metoda obsługuje adres .../
dt
/date/year
@GET
@Path
(
"/date/year"
)
public
int
odczytajRok
()
{
return
now
.
getYear
();
return
dt
.
getYear
();
}
// ta metoda obsługuje adres .../
api/now
/date/month
// ta metoda obsługuje adres .../
dt
/date/month
@GET
@Path
(
"/date/month"
)
public
int
odczytajMiesiac
()
{
return
now
.
getMonthValue
();
return
dt
.
getMonthValue
();
}
// ta metoda obsługuje adres .../
api/now
/date/day
// ta metoda obsługuje adres .../
dt
/date/day
@GET
@Path
(
"/date/day"
)
public
int
odczytajDzien
()
{
return
now
.
getDayOfMonth
();
return
dt
.
getDayOfMonth
();
}
// ta metoda obsługuje adres .../
api/now
/time
// ta metoda obsługuje adres .../
dt
/time
@GET
@Path
(
"/time"
)
public
LocalTime
odczytajCzas
()
{
return
now
.
toLocalTime
();
return
dt
.
toLocalTime
();
}
// ta metoda obsługuje adres .../dt/time/hour
@GET
@Path
(
"/time/hour"
)
public
int
odczytajGodzine
()
{
return
dt
.
getHour
();
}
// ta metoda obsługuje adres .../dt/time/minute
@GET
@Path
(
"/time/minute"
)
public
int
odczytajMinute
()
{
return
dt
.
getMinute
();
}
// ta metoda obsługuje adres .../
api/now
/time/second
// ta metoda obsługuje adres .../
dt
/time/second
@GET
@Path
(
"/time/second"
)
public
int
odczytajSekunde
()
{
return
now
.
getSecond
();
return
dt
.
getSecond
();
}
}
PC38-SpringJersey/src/main/java/sklep/rest/JerseyConfig.java
View file @
0ab9fd36
...
...
@@ -6,14 +6,14 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public
class
JerseyConfig
extends
ResourceConfig
{
/* Musimy zapewnić, aby podczas startu aplikacji na obiekcie ResourceConfig (z Jerseya)
* została wywołan metoda register dla wszystkich "resource classes", które wchodzą w skład aplikacji JAX-RS.
* została wywołan
a
metoda register dla wszystkich "resource classes", które wchodzą w skład aplikacji JAX-RS.
* W wersji Springowej nie ma klasy typu Application.
*/
public
JerseyConfig
()
{
register
(
Hello
.
class
);
//
register(DataCzas.class);
//
register(Kalkulator.class);
register
(
DataCzas
.
class
);
register
(
Kalkulator
.
class
);
// register(RProducts.class);
}
...
...
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