springboot系列文章(三)-创建第一个controller
来源:互联网 发布:a星算法的缺点 编辑:程序博客网 时间:2024/05/20 03:45
在上一节中,我们第二张截图中指定了package的信息,这样项目创建完成的时候,会自动创建包名。例如,packege选项填写的是org.csu.coder.lee,项目名project填写的是bootexample。那么,生成的项目中,就会有这样的目录结构src/main/java/org.csu.coder.lee的包,同时该包下会有一个BootexampleApplication的文件,run 该文件中的main方法,就会启动该web项目。
这里,一定要保证项目中所有的类是属于org.csu.coder.lee同包或者子包下,因为boot是默认扫描BootexampleApplication文件同包或者子包下的文件,类似于spring mvc中我们是要去配置scan来指定扫描的包路径的。
我们在org.csu.coder.lee的包下新建一个controller包,在controller包下新建一个IndexController的类,代码如下
import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;/** * Created by lixiang on 2017 09 20 13:43. */@RestControllerpublic class IndexController { @GetMapping("/index") @ResponseBody public Object index(String api_name) { return "success"; }}
boot中controller注解既支持@Controller 又加入新的@RestController注解,支持restful风格,同时boot支持@RequestMapping,又加入新的@GetMapping @PostMapping来简化注解支持rest风格,和springmvc中声明@ResponseBody一样,boot默认使用jackson来做Httpmessageconverter
阅读全文
0 0
- springboot系列文章(三)-创建第一个controller
- 创建第一个SpringBoot
- 创建第一个SpringBoot项目
- springboot(一) 创建第一个springboot项目
- 使用Intellij创建第一个Springboot程序
- 使用Intellij创建第一个Springboot程序
- 使用Intellij创建第一个Springboot程序
- 使用springboot创建第一个helloworld项目
- 使用Intellij创建第一个Springboot程序
- 使用Intellij创建第一个Springboot程序
- 使用Intellij创建第一个Springboot程序
- 【SpringBoot系列】一:5分钟构建第一个SpringBoot工程
- springboot学习(一)认识springboot及创建第一个springboot项目
- 如何开始创建第一个基于Spring MVC的Controller
- 在spring mvc应用中创建第一个Controller
- Springboot系列文章
- IDEA创建第一个springboot项目(1)
- SpringBoot学习笔记001--创建第一个spring boot应用
- 你可能还不知道的Linux 系统七件事
- DedeCMS中channelartlist自增参数global.itemindex
- java 获取某年某月星期几有哪几天
- 数据结构探险------队列篇
- static 之 静态初始化块
- springboot系列文章(三)-创建第一个controller
- 免费拿走我的代码可以,但请对使用我的时间付费
- java用制作小计算器
- BRVAH点击某一点实现单选
- 3208: 花神的秒题计划Ⅰ
- eclipse中获得程序执行的所用时间
- Unit3d开发 (二十一) 更改Apk的smali 排查Java层问题
- H.264与H.265的主要差异
- MySQL创建删除账号密码和重启命令