swaggerspringfox生成的日期

问题描述

我在招摇中定义了一个字段:

CreateCouponsTable

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('coupons',function (Blueprint $table) {
        $table->increments('id');
        $table->nullableMorphs('redeemable');
        $table->timestamp('redeemed_at')->nullable();
        $table->unsignedBigInteger('user_id')->nullable();
        $table->string('code')->nullable();
        $table->timestamps();

        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
    });
}

我希望将appStartedDate生成为字符串“ 2020-09-20” 。相反,它是作为LocalDate生成的

appStartedDate:
   type: string
   format: date

我正在使用 springfox-swagger2 v2.9.2

我们该怎么做才能保持原始规格(格式:日期),并仍然在“ yyyy-mm-dd” forwat中生成日期

解决方法

可以尝试添加@JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd") 如下图所示

@JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd")
Date appStartedDate;

以上相信可以解决您的问题。

您也可以使用LocalDate代替Date

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...