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
5fa6176b
Commit
5fa6176b
authored
May 11, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
przykłady obłusig parametrów
parent
0f34b3fc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
0 deletions
+128
-0
Kalkulator.java
PC26-RestSerwer/src/main/java/rest/Kalkulator.java
+34
-0
Parametry.java
PC26-RestSerwer/src/main/java/rest/Parametry.java
+94
-0
No files found.
PC26-RestSerwer/src/main/java/rest/Kalkulator.java
0 → 100644
View file @
5fa6176b
package
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
;
}
}
PC26-RestSerwer/src/main/java/rest/Parametry.java
0 → 100644
View file @
5fa6176b
package
rest
;
import
jakarta.ws.rs.*
;
import
jakarta.ws.rs.core.NewCookie
;
import
jakarta.ws.rs.core.Response
;
import
java.time.LocalDateTime
;
import
java.util.Arrays
;
@Path
(
"/parametry"
)
@Produces
(
"text/plain"
)
public
class
Parametry
{
@Path
(
"/witaj"
)
@GET
// w Springu byłoby tak: @GetMapping(path="/witaj", produces="text/plain")
public
String
witaj
(
@QueryParam
(
"imie"
)
String
imie
)
{
return
"Witaj "
+
imie
;
}
// .../parametry/query?a=Ala&b=Basia&t=Tomek&t=Tadeusz&t=Tola
@GET
@Path
(
"/query"
)
public
String
query
(
@QueryParam
(
"a"
)
String
a
,
@QueryParam
(
"b"
)
String
b
,
@QueryParam
(
"t"
)
String
[]
t
)
{
return
"Parametr a = "
+
a
+
"\nParametr b = "
+
b
+
"\nTablica: "
+
Arrays
.
toString
(
t
);
}
// .../parametry/query;a=Ala;b=Basia;t=Tomek;t=Tadeusz;t=Tola
@GET
@Path
(
"/matrix"
)
public
String
matrix
(
@MatrixParam
(
"a"
)
String
a
,
@MatrixParam
(
"b"
)
String
b
,
@MatrixParam
(
"t"
)
String
[]
t
)
{
return
"Parametr a = "
+
a
+
"\nParametr b = "
+
b
+
"\nTablica: "
+
Arrays
.
toString
(
t
);
}
// /parametry/path/Ala/123/98765qwerty
// przykład realnego użycia: /products/{id}
@GET
@Path
(
"/path/{a}/{b}/{cyfry:\\d+}{litery:[A-Za-z]*}"
)
public
String
pathParam
(
@PathParam
(
"a"
)
String
a
,
@PathParam
(
"b"
)
String
b
,
@PathParam
(
"cyfry"
)
String
cyfry
,
@PathParam
(
"litery"
)
String
litery
)
{
return
"Parametr a = "
+
a
+
"\nParametr b = "
+
b
+
"\nCyfry: "
+
cyfry
+
"\nLitery: "
+
litery
;
}
@GET
@Path
(
"/headers"
)
public
String
headers
(
@HeaderParam
(
"accept"
)
String
accept
,
@HeaderParam
(
"user-agent"
)
String
agent
)
{
return
"Accept: "
+
accept
+
"\nUser-Agent: "
+
agent
;
}
@GET
@Path
(
"/cookies"
)
public
String
cookies
(
@CookieParam
(
"ciacho"
)
String
ciacho
,
@CookieParam
(
"JSESSIONID"
)
String
sessionId
)
{
return
"Ciacho: "
+
ciacho
+
"\nSesja: "
+
sessionId
;
}
@GET
@Path
(
"/ustaw"
)
// ustawia ciacho
public
Response
ustawCiacho
()
{
String
ciacho
=
LocalDateTime
.
now
().
toString
();
return
Response
.
ok
()
.
cookie
(
new
NewCookie
.
Builder
(
"ciacho"
).
value
(
ciacho
).
build
())
.
type
(
"text/plain"
)
.
entity
(
"Ustawiam ciacho na: "
+
ciacho
)
.
build
();
}
}
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