@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(){
}
}