hyperf注解路由官方例子:
上述例子使用的是@RequestMapping
,当使用其他Mapping
注解时,写法稍稍有点不同。
<?php
declare(strict_types=1);
namespace App\Controller;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
/**
* @Controller()
* Class IndexController
* @package App\Controller
*/
class IndexController extends AbstractController
{
/**
*@GetMapping(path="index_function")
* @return string
*/
public function indexFunction()
{
return 'indexFunction';
}
}
运行结果:
总结:当使用例如GetMapping
时,只需要写path,path定义的是当前方法,path需要跟请求url的一致。