@RestController
@RequestMapping(value = "/mark")
public class MarkController
这是我们经常看到的两个注解,每次都要写两行,为了提高速度,所以要封装一下这俩个注解。不知道为什么spring为什么不封装一个,比如他官方提供的PostMapping
等,以下是注解的代码。
/**@Title: TRestController.java
* @Description: 简化 @RestController @RequestMapping
* @author nelson
* @date 2018年4月14日 下午1:50:33
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RestController
@RequestMapping
public @interface TRestController {
/**
* Alias for {@link RequestMapping#name}.
*/
@AliasFor(annotation = RequestMapping.class)
String name() default "";
/**
* Alias for {@link RequestMapping#value}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] value() default {};
/**
* Alias for {@link RequestMapping#path}.
*/
@AliasFor(annotation = RequestMapping.class)
String[] path() default {};
}
封装后就这样使用即可,是不是省了一行代码
@TRestController("forum")
public class ForumController
@Target(ElementType.TYPE)
指定只能在类上使用
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有