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
9b346521
Commit
9b346521
authored
Jun 01, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SpringJersey - dodatkowe przykłady bez bazy danych
parent
565ec0d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
+106
-0
DataCzas.java
PC38-SpringJersey/src/main/java/sklep/rest/DataCzas.java
+72
-0
Kalkulator.java
PC38-SpringJersey/src/main/java/sklep/rest/Kalkulator.java
+34
-0
No files found.
PC38-SpringJersey/src/main/java/sklep/rest/DataCzas.java
0 → 100644
View file @
9b346521
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"
)
// @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
();
{
// ten blok wykona się podczas tworzenia każdego obiektu
System
.
out
.
println
(
"Powstał obiekt DataCzas z czasem równym "
+
now
);
}
// ta metoda obsługuje adres .../api/now
@GET
public
LocalDateTime
odczytajDataICzas
()
{
return
now
;
}
// ta metoda obsługuje adres .../api/now/date
@GET
@Path
(
"/date"
)
public
LocalDate
odczytajDate
()
{
return
now
.
toLocalDate
();
}
// ta metoda obsługuje adres .../api/now/date/year
@GET
@Path
(
"/date/year"
)
public
int
odczytajRok
()
{
return
now
.
getYear
();
}
// ta metoda obsługuje adres .../api/now/date/month
@GET
@Path
(
"/date/month"
)
public
int
odczytajMiesiac
()
{
return
now
.
getMonthValue
();
}
// ta metoda obsługuje adres .../api/now/date/day
@GET
@Path
(
"/date/day"
)
public
int
odczytajDzien
()
{
return
now
.
getDayOfMonth
();
}
// ta metoda obsługuje adres .../api/now/time
@GET
@Path
(
"/time"
)
public
LocalTime
odczytajCzas
()
{
return
now
.
toLocalTime
();
}
// ta metoda obsługuje adres .../api/now/time/second
@GET
@Path
(
"/time/second"
)
public
int
odczytajSekunde
()
{
return
now
.
getSecond
();
}
}
PC38-SpringJersey/src/main/java/sklep/rest/Kalkulator.java
0 → 100644
View file @
9b346521
package
sklep
.
rest
;
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.Path
;
import
jakarta.ws.rs.PathParam
;
@Path
(
"/calc"
)
public
class
Kalkulator
{
@GET
@Path
(
"/{x}+{y}"
)
public
long
dodaj
(
@PathParam
(
"x"
)
long
a
,
@PathParam
(
"y"
)
long
b
)
{
return
a
+
b
;
}
@GET
@Path
(
"/{x}-{y}"
)
public
long
odejmij
(
@PathParam
(
"x"
)
long
a
,
@PathParam
(
"y"
)
long
b
)
{
return
a
-
b
;
}
@GET
@Path
(
"/{x}*{y}"
)
public
long
pomnoz
(
@PathParam
(
"x"
)
long
a
,
@PathParam
(
"y"
)
long
b
)
{
return
a
*
b
;
}
@GET
@Path
(
"/{x}/{y}"
)
public
long
podziel
(
@PathParam
(
"x"
)
long
a
,
@PathParam
(
"y"
)
long
b
)
{
return
a
/
b
;
}
}
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