Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20240528-BJava
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
20240528-BJava
Commits
dfa0e9e3
Commit
dfa0e9e3
authored
Jun 25, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generowanie PDF także pod adresem /products
parent
447cbe44
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
RProducts.java
PC27-RestSerwer/src/main/java/sklep/rest/RProducts.java
+9
-2
Klient12_RestClient_String.java
...src/main/java/rest_klient/Klient12_RestClient_String.java
+1
-1
No files found.
PC27-RestSerwer/src/main/java/sklep/rest/RProducts.java
View file @
dfa0e9e3
...
...
@@ -9,6 +9,7 @@ import sklep.db.DBException;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.model.Product
;
import
sklep.model.ProductList
;
import
java.math.BigDecimal
;
import
java.net.URI
;
...
...
@@ -28,7 +29,7 @@ import java.util.List;
@Path
(
"/products"
)
public
class
RProducts
{
@GET
@Produces
({
"application/json"
,
"
application/xml"
,
"
text/plain;charset=UTF-8"
})
@Produces
({
"application/json"
,
"text/plain;charset=UTF-8"
})
// @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
public
List
<
Product
>
allProducts
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
...
...
@@ -37,6 +38,12 @@ public class RProducts {
}
}
@GET
@Produces
({
"application/xml"
,
"application/pdf"
})
public
ProductList
allProductsXml
()
throws
DBException
{
return
new
ProductList
(
allProducts
());
}
// Może też być tak, że kilka metod działa pod tym samym adresem, ale służą one do tworzenia odpowiedzi w różnych formatach.
// Przykład: tworzenie HTML w oddzielnej metodzie
@GET
...
...
@@ -54,7 +61,7 @@ public class RProducts {
@GET
@Path
(
"/{id}"
)
@Produces
({
"application/json"
,
"application/xml"
,
"text/plain;charset=UTF-8"
})
@Produces
({
"application/json"
,
"application/xml"
,
"text/plain;charset=UTF-8"
,
"application/pdf"
})
// przykładowo /api/products/3
public
Product
oneProduct
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
...
...
PC28-RestKlient/src/main/java/rest_klient/Klient12_RestClient_String.java
View file @
dfa0e9e3
...
...
@@ -22,7 +22,7 @@ public class Klient12_RestClient_String {
// readEntity(OKREŚLENIE TYPU) stara się odczytać tresc odpowiedzi jako obiekt podanego typu
// Obsługiwane typy to m.in: byte[], String, InputStream, File
// Dodając odpowiednie "Me
ass
geBodyReader", możemy obsługiwać dowolne typy.
// Dodając odpowiednie "Me
ssa
geBodyReader", możemy obsługiwać dowolne typy.
// W szczególności, gdy dodamy do projektu obsługę XML lub JSON (zob. zależności Mavena),
// będziemy mogli odczytywać dane w postaci obiektów naszego modelu, np. Product.
String
dane
=
response
.
readEntity
(
String
.
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