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

结果: php bin/hyperf.php describe:routes 查看路由信息

image.png

问题: #[RequestMapping(path: "/index", methods: ["post"])]
处在这个注解上,path: "/index"不应该加 “/”
实际为:path: "index"

修改后:


image.png

恢复正常。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容