在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