spring boot学习(三)---Controller
来源:互联网 发布:ps4辐射4美女捏脸数据 编辑:程序博客网 时间:2024/06/06 12:51
三 Controller
1. 常用注解
@Controller 接收http请求
@RestController 是@Controller和@ResponseBody的结合
@RequestMapping url地址映射
@PathVariable 获取url参数
@RequestParam 获取请求参数的值
@GetMapping 组合注解 简化get方法
2. 模板配置
在resources目录下新建templates,在下面新建html模板(模板中随便写点东西,便于观察)
pom.xml中添加配置
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
HelloController改成如下配置(主要修改类上的注解,和方法上的返回值)
package com.boot.web;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@Controllerpublic class HelloController { @Value("${stu.name}") private String cupSize;//配置文件注入 @Value("${stu.context}") private String context; @RequestMapping(value="/hello" ,method = RequestMethod.GET) public String say(){ return "index"; //return "spring boot!"; }}
在浏览器中输入localhost:8080/hello 可以看到模板
阅读全文
0 0
- spring boot学习(三)---Controller
- spring boot学习笔记(三):controller用法及数据库操作
- spring boot 学习之controller
- Spring Boot学习(一)之Controller的使用
- Spring Boot学习(三)
- Spring boot 学习笔记(三)
- Spring Boot 学习笔记(三)
- Spring Boot Controller
- spring boot 之 controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot Controller
- Spring Boot Controller
- Spring boot(三)
- 《spring-boot学习》-12-@controller和@RestController的区别?
- Spring Boot 学习——Controller的使用
- (三) Spring Boot学习笔记之Spring Boot整合Logback
- 上传头像
- scala主构造器的多种玩法
- springboot启动方式
- hashCode与equals详解
- execute、executeQuery和executeUpdate之间的区别
- spring boot学习(三)---Controller
- UVA-12174 Shuffle
- Android APT 技术浅谈
- [回文自动机优化转移] Central Europe Regional Contest 2014 G. Virus synthesis
- centos配置dns服务器
- CDH5.11.2在centos6.4上完整安装分享
- 大数据
- Maven讲解之 依赖管理
- 古老的智力题——奇怪的游戏