Commit e93b1a52 by Patryk Czarnik

RTime - wydzielenie obiektu z datą na poziom klasy

parent 1104af1d
package rest; package rest;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import jakarta.ws.rs.GET; import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path; import jakarta.ws.rs.Path;
@Path("/dt") @Path("/dt")
public class RTime { 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 // działa pod adresem: /dt
@GET @GET
public String getDateTime() { public String getDateTime() {
return LocalDateTime.now().toString(); return dt.toString();
} }
// działa pod adresem: /dt/date // działa pod adresem: /dt/date
@GET @GET
@Path("/date") @Path("/date")
public String getDate() { public String getDate() {
return LocalDate.now().toString(); return dt.toLocalDate().toString();
} }
@GET @GET
@Path("/time") @Path("/time")
public String getTime() { public String getTime() {
return LocalTime.now().toString(); return dt.toLocalTime().toString();
} }
@GET @GET
@Path("/time/second") @Path("/time/second")
public int getSecond() { public int getSecond() {
return LocalTime.now().getSecond(); return dt.getSecond();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment