@ResponseBody和@Restcontroller区别以及常用注解大全

@ResponseBody:只返回json数据
@Restcontroller:控制层访问路径+返回json数据

补充:
@Autowerid 自动注入bean对象,并且每个bean对象是唯一的,这是从bean工厂中拿来用;
@Component(是将bean注入到bean工厂):他一个相当于是@Service,@Controller,@Repository中的任何一个,下面是@Controller 源码一看便知

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 */
	@AliasFor(annotation = Component.class)
	String value() default "";

}

@RequestParm :这个有时不加,我们也能获取到,但是在特定情况下必须要用:
1 当前台的key和后台的key不同时

public void  test(@RequestParm("key”) String  key22222){}

2 可以设置请求参数为不是必须有的required=false,好处是,当你没有写请求参数时不会报错,反之

public void  test(@RequestParm("key”) String  key22222,required=false){}

3 在设置默认值得时候,比如,分页时要从前台获取当前页数和每页条数,这是就会有你前台发来的数据是空的,这时就需要用到默认值

public void  test(@RequestParm(defaultValue=1) String  currentPage,required=false){}

@RequestMapping :提供url访问路径:/user/test 就能访问test方法

@RequestMapping(“/user”) 
public class UserController(){
	@RequestMapping(“/test”) 
	public void test(){
	}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值