hyperf3.1 #[Controller(prefix: "/api/v1")] 不生效原因

代碼如下:

<?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

結(jié)果: php bin/hyperf.php describe:routes 查看路由信息

image.png

問題: #[RequestMapping(path: "/index", methods: ["post"])]
處在這個注解上,path: "/index"不應該加 “/”
實際為:path: "index"

修改后:


image.png

恢復正常。

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容