Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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
java_dzienna_15_09
Commits
2c7d40f1
Commit
2c7d40f1
authored
Oct 07, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adnotacje @Consumes i @Produces na poziomie klasy
parent
403c65f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
RProductsJSON.java
PC34-RestSerwer/src/main/java/sklep/rest/RProductsJSON.java
+7
-6
No files found.
PC34-RestSerwer/src/main/java/sklep/rest/RProductsJSON.java
View file @
2c7d40f1
...
@@ -20,12 +20,18 @@ import sklep.model.Product;
...
@@ -20,12 +20,18 @@ import sklep.model.Product;
import
sklep.photo.PhotoUtil
;
import
sklep.photo.PhotoUtil
;
// W tej wersji dane rekordów są udostępniane i pobierane w formacie JSON. Tylko zdjęcia są w formacie JPEG.
// W tej wersji dane rekordów są udostępniane i pobierane w formacie JSON. Tylko zdjęcia są w formacie JPEG.
// Adnotacje Produces i Consumes na pozimie klasy stają się domyślnym ustawieniem dla wszystkich metod,
// ale metoda może to "nadpisac" (np. getPhoto)
// Inaczej niż w Springu, tutaj można napisać Consumes na poziomie klasy, ale będzie to dotyczyć
// tylko tych metod, które odbierają jakieś dane (POST i PUT, a nie GET).
// Produces dotyczy tylko tych metod, które coś zwracają, ale nie metod typu void.
@Path
(
"/products.json"
)
@Path
(
"/products.json"
)
@Produces
(
"application/json"
)
@Consumes
(
"application/json"
)
public
class
RProductsJSON
{
public
class
RProductsJSON
{
@GET
@GET
@Produces
(
"application/json"
)
public
List
<
Product
>
readAll
()
throws
DBException
{
public
List
<
Product
>
readAll
()
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
...
@@ -34,7 +40,6 @@ public class RProductsJSON {
...
@@ -34,7 +40,6 @@ public class RProductsJSON {
}
}
@GET
@GET
@Produces
(
"application/json"
)
@Path
(
"/{id}"
)
@Path
(
"/{id}"
)
public
Product
readOne
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
public
Product
readOne
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
...
@@ -44,7 +49,6 @@ public class RProductsJSON {
...
@@ -44,7 +49,6 @@ public class RProductsJSON {
}
}
@GET
@GET
@Produces
(
"application/json"
)
@Path
(
"/{id}/price"
)
@Path
(
"/{id}/price"
)
public
BigDecimal
getPrice
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
public
BigDecimal
getPrice
(
@PathParam
(
"id"
)
int
productId
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
...
@@ -55,7 +59,6 @@ public class RProductsJSON {
...
@@ -55,7 +59,6 @@ public class RProductsJSON {
}
}
@PUT
@PUT
@Consumes
(
"application/json"
)
@Path
(
"/{id}/price"
)
@Path
(
"/{id}/price"
)
public
void
setPrice
(
@PathParam
(
"id"
)
int
productId
,
BigDecimal
newPrice
)
throws
DBException
,
RecordNotFound
{
public
void
setPrice
(
@PathParam
(
"id"
)
int
productId
,
BigDecimal
newPrice
)
throws
DBException
,
RecordNotFound
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
...
@@ -68,8 +71,6 @@ public class RProductsJSON {
...
@@ -68,8 +71,6 @@ public class RProductsJSON {
}
}
@POST
@POST
@Consumes
(
"application/json"
)
@Produces
(
"application/json"
)
public
Product
addProduct
(
Product
product
)
throws
DBException
{
public
Product
addProduct
(
Product
product
)
throws
DBException
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
ProductDAO
productDAO
=
db
.
productDAO
();
...
...
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