简体   繁体   English

如何将时间和日期值从邮递员发送到我的 REST API

[英]How to send Time and Date value from Postman to my REST API

I have a Schedules class as a Table in postgres with jamMulai, jamSelesai variable with a LocalTime data type, and tglTayang variable with a LocalDate variable我在 postgres 中有一个带有 jamMulai 的表、带有 LocalTime 数据类型的 jamSelesai 变量和带有 LocalDate 变量的 tglTayang 变量的 Schedules 类

@Entity
@Getter
@Setter
@Table(name = "schedules")
public class Schedules implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "serial")
    private Long scheduleId;


    @Column(name = "tgl_tayang",columnDefinition = "DATE")
    private LocalDate tglTayang;


    @Column(name = "jam_mulai",columnDefinition = "TIME")
    private LocalTime jamMulai;


    @Column(name = "jam_selesai" ,columnDefinition = "TIME")
    private LocalTime jamSelesai;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "film_id")
    private Films filmId;

This is my service method for the Schedules class这是我的 Schedules 类的服务方法

@Override
    public void saveSchedule(String jamMulai, String jamSelesai, String tglTayang, Long filmId) {
        Schedules schedules = new Schedules();
        schedules.setJamMulai(LocalTime.parse(jamMulai));
        schedules.setJamSelesai(LocalTime.parse(jamSelesai));
        schedules.setTglTayang(LocalDate.parse(tglTayang));
        Films films = filmsService.findFilmById(filmId);
        schedules.setFilmId(films);
        schedulesRepository.save(schedules);

    }

and this is my controller method这是我的控制器方法

@PostMapping("/admin/add-schedule")
    public String addSchedule(@RequestBody Map<String, Object> schedule) {
        schedulesService.saveSchedule((String) schedule.get("jamMulai"), (String) schedule.get("jamSelesai"), (String) schedule.get("tglTayang"), (Long) schedule.get("filmId"));
        return "Add Films Success!";
    }

in the Postgres database the data type for jamMulai, jamSelesai, and tglTayang is time without time zone and date.在 Postgres 数据库中,jamMulai、jamSelesai 和 tglTayang 的数据类型是没有时区和日期的时间。

But when I try to request Post using Postman但是当我尝试使用 Postman 请求 Post

{   
    "jamMulai":"20:00:00",
    "jamSelesai":"23:00:00",
    "tglTayang":"2020-05-12",
    "filmId":2
}

I get我明白了

{
    "timestamp": "2022-05-17T13:41:52.771+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/cinema/schedules/admin/add-schedule"
}

I've tried changing the data type in Schedules class to a different time and date but it still doesn't work.我尝试将 Schedules 类中的数据类型更改为不同的时间和日期,但它仍然不起作用。

How can I fix this?我怎样才能解决这个问题? Thanks谢谢

ps: I know there's a similar question to this, but it doesn't solve my issue ps:我知道有一个类似的问题,但这并不能解决我的问题

You said: in the Postgres database the data type for jamMulai, jamSelesai, and tglTayang is time without time zone and date.您说:在 Postgres 数据库中,jamMulai、jamSelesai 和tglTayang的数据类型是没有区和日期的时间。

Why do you define:为什么要定义:

@Column(name = "tgl_tayang",columnDefinition = "DATE")
private LocalDate tglTayang;

Shouldn't it be:不应该是:

@Column(name = "tgl_tayang",columnDefinition = "TIME")
private LocalTime tglTayang;

? ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 rest api - 如何在rest api调用中发送邮递员的身体参数 - rest api - how to send body parameters of postman in rest api call 如何捕获其余api控制器上的文件以及使用Postman发送它的方法 - how to catch a file on the rest api controller and what method to send it with Postman 如何在POST方法的REST API中发送日期 - How to send Date in REST API in POST method 如何在REST API中强制执行日期值输入? - How to enforce a date value input in a REST API? 我想将列表(它是对象的成员)从 Postman 发送到 Spring REST ZDB974238714CA8ACED638 - I want to send a List(which is a member of an object) from Postman to Spring REST API 我正在使用 Postman 将数据传递给 REST api 但我的变量显示 Z37A6259CC0C1DAE0BDZA 值 - I am using Postman, to pass the data to a REST api but my variable is showing null value 如何将数据从servlet发送到rest api - how to send data from servlet to rest api 如何在 Z03D476861AFD3841110F2CB80CCFA8 中请求 Rest API eclipse 服务? - How to request Rest API eclipse service in postman? 如何使用邮递员休息客户端发送对象以调用REST服务 - how to send object using postman rest client to call REST service 为什么我的 Postman 找不到我的 Spring REST ZDB974238714CA8DE634A7CE1D083A14? - Why can't my Postman find my Spring REST API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM