如何解决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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。