SpringBoot入门之常用注解
来源:互联网 发布:一键抠图软件电脑 编辑:程序博客网 时间:2024/05/29 14:39
@Transactional //事务
@Value("${cupSize}")
private String cupSize; // 将配置文件中的内容注入到属性变量中@Component //注入配置
@ConfigurationProperties(prefix = "girl") //获取前缀是girl的配置/*把配置写到一个类中*/
@Controller //处理http请求
@RestController Spring4之后新加的注解,原来返回json需要@ResponseBody配合@Controller
@RequestMapping //配置url映射
@RequestMapping(value = {"/hello","/hi"},method = RequestMethod.GET) //可通过/hello或者/hi访问接口
注:单独使用@Controller 需要在pom.xml中配置模板(使用模板在性能上会造成很大的损耗,不推荐使用)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
并且在resources目录下新建一个template文件 在此文件中新建一个 index.html文件
在接口中则只需返回html文件即可 ,
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String say(){ return "index"; }
传单个参数示例:
方案1:
@RequestMapping(value = {"/{id}/hello","/hi/{id}"},method = RequestMethod.GET)
public String say(@PathVariable("id") Integer id){
return "--->id:"+id;
}
访问:http://127.0.0.1:8088/girl/100/hello 或者http://127.0.0.1:8088/girl/hi/100
方案2:
@RequestMapping(value = {"/hello","/hi"},method = RequestMethod.GET)
// @GetMapping(value = "/say")
public String say(@RequestParam(value = "id",required = false,defaultValue = "0") Integer id){
return "--->id:"+id;
}
/*
required 是否必填
defaultValue 默认值
@GetMapping简化@RequestMapping
*/
- SpringBoot入门之常用注解
- springboot入门(二)--springboot常用注解及配置
- springBoot学习之常用注解 --1
- springboot 常用注解
- springboot常用注解二
- 常用springboot注解
- springboot常用注解总结
- SpringBoot常用注解
- SpringBoot常用注解
- SpringBoot常用注解
- Springboot 常用注解
- 【SpringBoot】常用注解
- Springboot 常用注解
- SpringBoot一些常用注解
- springboot常用注解集锦
- springboot常用注解
- Springboot 常用注解
- springBoot Restfull 常用注解
- 关于(function(){…})()立即执行函数写法理解
- 微信商户号25位招商银行号
- Elasticsearch
- UVA-12260-Free Goodies
- Android本地单元测试-mockito的使用(Kotlin版本)
- SpringBoot入门之常用注解
- Python学习之路---Python 字符串
- Python(11) APScheduler
- MySQL 修改数据表--删除约束
- Windows 7下通过anaconda安装tensorflow
- .NET快速信息化系统开发框架 V3.2 -> Web 用户管理模块编辑界面-组织机构选择支持级联选择
- 2017idea的激活方法
- 浅谈常见的target=_blank
- 设计一个学生类Student