Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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
javab_20230928
Commits
b3f43b8b
Commit
b3f43b8b
authored
Nov 10, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Jersey: proste przykłady bez bazy danych
parent
c2d729fa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
JerseyConfig.java
PC39-SpringJersey/src/main/java/sklep/rest/JerseyConfig.java
+18
-0
RHello.java
PC39-SpringJersey/src/main/java/sklep/rest/RHello.java
+14
-0
RTime.java
PC39-SpringJersey/src/main/java/sklep/rest/RTime.java
+40
-0
No files found.
PC39-SpringJersey/src/main/java/sklep/rest/JerseyConfig.java
0 → 100644
View file @
b3f43b8b
package
sklep
.
rest
;
import
org.glassfish.jersey.server.ResourceConfig
;
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.
* W wersji Springowej nie ma klasy typu Application.
*/
public
JerseyConfig
()
{
register
(
RHello
.
class
);
register
(
RTime
.
class
);
}
}
PC39-SpringJersey/src/main/java/sklep/rest/RHello.java
0 → 100644
View file @
b3f43b8b
package
sklep
.
rest
;
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.Path
;
@Path
(
"/hello"
)
public
class
RHello
{
@GET
public
String
hello
()
{
return
"Hello <b>REST</b>"
;
}
}
PC39-SpringJersey/src/main/java/sklep/rest/RTime.java
0 → 100644
View file @
b3f43b8b
package
sklep
.
rest
;
import
java.time.LocalDateTime
;
import
jakarta.ws.rs.GET
;
import
jakarta.ws.rs.Path
;
@Path
(
"/dt"
)
public
class
RTime
{
// Obiekt tej klasy jest tworzony za każdym razem do obsługi każdego pojedynczego zapytania.
private
LocalDateTime
dt
=
LocalDateTime
.
now
();
{
System
.
out
.
println
(
"Jest tworzony obiekt RTime , dt = "
+
dt
);
}
// działa pod adresem: /dt
@GET
public
String
getDateTime
()
{
return
dt
.
toString
();
}
// działa pod adresem: /dt/date
@GET
@Path
(
"/date"
)
public
String
getDate
()
{
return
dt
.
toLocalDate
().
toString
();
}
@GET
@Path
(
"/time"
)
public
String
getTime
()
{
return
dt
.
toLocalTime
().
toString
();
}
@GET
@Path
(
"/time/second"
)
public
int
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