Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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_20230617
Commits
30b34101
Commit
30b34101
authored
Aug 20, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wersje HTML w ramach multiformatu
parent
d7f5ffd7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
RProducts.java
PC32-RestSerwer/src/main/java/sklep/rest/RProducts.java
+23
-0
No files found.
PC32-RestSerwer/src/main/java/sklep/rest/RProducts.java
View file @
30b34101
...
@@ -40,6 +40,21 @@ public class RProducts {
...
@@ -40,6 +40,21 @@ public class RProducts {
}
}
}
}
// 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
@Produces
(
"text/html;charset=UTF-8"
)
public
String
readAllHTML
()
throws
DBException
{
List
<
Product
>
products
=
readAll
();
StringBuilder
txt
=
new
StringBuilder
(
"<!DOCTYPE html>\n<html><body>\n"
);
txt
.
append
(
"<h1>Lista produktów</h1>\n"
);
for
(
Product
product
:
products
)
{
txt
.
append
(
product
.
toHtml
()).
append
(
'\n'
);
}
txt
.
append
(
"</body></html>"
);
return
txt
.
toString
();
}
@GET
@GET
@Produces
({
"application/json"
,
"application/xml"
,
"text/plain"
})
@Produces
({
"application/json"
,
"application/xml"
,
"text/plain"
})
@Path
(
"/{id}"
)
@Path
(
"/{id}"
)
...
@@ -50,6 +65,14 @@ public class RProducts {
...
@@ -50,6 +65,14 @@ public class RProducts {
}
}
}
}
@GET
@Produces
(
"text/html;charset=UTF-8"
)
@Path
(
"/{id}"
)
public
String
readOneHTML
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
Product
product
=
readOne
(
productId
);
return
"<!DOCTYPE html>\n<html><body>"
+
product
.
toHtml
()
+
"</body></html>"
;
}
// Dostęp do pojedynczego pola w rekordzie - nie ma obowiązku implementowania takich metod
// Dostęp do pojedynczego pola w rekordzie - nie ma obowiązku implementowania takich metod
// i nie robi robi się tego zbyt często, ale pokazujemy, że można (gdyby klient często potrzebował dostępu do wybranego szczegółu)
// i nie robi robi się tego zbyt często, ale pokazujemy, że można (gdyby klient często potrzebował dostępu do wybranego szczegółu)
@GET
@GET
...
...
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