临沂专业网站建设设计公司,嵌入式开发难学吗,常州网红餐厅有哪些,工商注册公司的流程刚入门小白#xff0c;详细请看这篇SpringBoot各种Controller写法_springboot controller-CSDN博客 Spring Boot 提供了Controller和RestController两种注解。
Controller
返回一个string#xff0c;其内容就是指向的html文件名称。 Controller
public class HelloControll…刚入门小白详细请看这篇SpringBoot各种Controller写法_springboot controller-CSDN博客 Spring Boot 提供了Controller和RestController两种注解。
Controller
返回一个string其内容就是指向的html文件名称。 Controller
public class HelloController {RequestMapping(/hello)public String index(ModelMap map) {map.addAttribute(name, ge);return hello;}
}
RestController
将返回对象数据转换为JSON格式。
RestController
public class HelloController {RequestMapping(/user)public User getUser() {User user new User();user.setUsername(ge);user.setPassword(kaimen);return user;}
}
RequestMapping
负责URL路由映射。
如果添加在Controller类上则该Controller中所有路由映射都会加上该映射规则
如果添加在方法上则只对当前方法生效。
属性value, method, consumes, produces, params, headers 等
RequestMapping(value /getData, method RequestMethod.GET)public String getData() {return hello;
}
Method 匹配也可以用 GetMapping, PostMapping 等代替。