代码如下:
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Controller;
use App\Controller\Internal\InterApi;
use Exception;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
#[Controller(prefix: "/api/v1")]
class IndexController extends AbstractController
{
#[Inject]
protected InterApi $api;
#[RequestMapping(path: "/index", methods: ["post"])]
public function index()
{
$returnParam['aa'] =12;
$returnParam['bb'] =23;
return ['data' => $returnParam];
}
}
预想的路由: /api/v1/index
结果: php bin/hyperf.php describe:routes
查看路由信息
image.png
问题: #[RequestMapping(path: "/index", methods: ["post"])]
处在这个注解上,path: "/index"
不应该加 “/”
实际为:path: "index"
修改后:
image.png
恢复正常。