API平台3中非标识路径参数的处理方法
创始人
2024-09-08 00:30:51
0

在API Platform 3中,对于非标识路径参数,需要使用@QueryParameter注解来处理。以下是一个示例代码:

use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\NumericFilter;

/**
 * @ApiResource(attributes={
 *     "normalization_context"={"groups"={"book_read"}},
 *     "denormalization_context"={"groups"={"book_write"}},
 * })
 */
class Book
{
    /**
     * The unique identifier of the book.
     *
     * @var int
     *
     * @ApiProperty(identifier=true)
     * @Groups({"book_read", "book_write"})
     */
    protected $id;

    /**
     * The title of the book.
     *
     * @var string
     *
     * @Assert\NotBlank
     * @Groups({"book_read", "book_write"})
     */
    protected $title;

    /**
     * The author of the book.
     *
     * @var string|null
     *
     * @Groups({"book_read", "book_write"})
     */
    protected $author;

    /**
     * The publication date of the book.
     *
     * @var \DateTimeInterface|null
     *
     * @Groups({"book_read", "book_write"})
     */
    protected $publicationDate;

    /**
     * The genre of the book.
     *
     * @var string|null
     *
     * @Groups({"book_read", "book_write"})
     */
    protected $genre;

    /**
     * The number of pages in the book.
     *
     * @var int|null
     *
     * @Groups({"book_read", "book_write"})
     */
    protected $pages;

    /**
     * The rating of the book.
     *
     * @var float|null
     *
     * @Assert\Range(min=0, max=10)
     * @Groups

相关内容

热门资讯

大家学习交流(微扑克工具)外挂... 大家学习交流(微扑克工具)外挂透明挂辅助app(透视)软件透明挂(2023已更新)(哔哩哔哩);玩家...
分享一款!线上德州有后台(We... 1、分享一款!线上德州有后台(WePoke)外挂透明挂辅助器安装(辅助挂)线上教程(有挂猫腻)-哔哩...
发现一款(WPK)外挂透明挂辅... 发现一款(WPK)外挂透明挂辅助APP(透视)软件透明挂(有挂教程)-哔哩哔哩;(需添加指定薇841...
每日必看(cloudpoker... 每日必看(cloudpoker云扑克)外挂透明挂辅助软件(辅助挂)透视辅助(2025已更新)(哔哩哔...
透视透明!WPK辅助(WePo... 透视透明!WPK辅助(WePoke)外挂透明挂辅助挂(辅助挂)高科技教程(确实有挂)-哔哩哔哩;原来...
记者爆料(眯眯扑克)外挂透明挂... 记者爆料(眯眯扑克)外挂透明挂辅助器安装(透视)透视辅助(有挂头条)-哔哩哔哩;(需添加指定薇757...
安装程序教程(德扑之星解析)外... 安装程序教程(德扑之星解析)外挂透明挂辅助脚本(辅助挂)辅助透视(2023已更新)(哔哩哔哩);德扑...
透视安卓版(wpk教程)外挂透... 1、透视安卓版(wpk教程)外挂透明挂辅助器安装(透视)发牌规律(有挂分享)-哔哩哔哩(UU pok...
玩家必知教程!手机德州app(... 玩家必知教程!手机德州app(wepoke)外挂透明挂辅助工具(透视)黑科技教程(有挂方法)-哔哩哔...
透明辅助(wpk安卓版)外挂透... 透明辅助(wpk安卓版)外挂透明挂辅助APP(辅助挂)软件透明挂(2022已更新)(哔哩哔哩);科技...