在IDEA中开发Springboot应用和Eclipse里面一样,本质上都是一个maven 项目。 但是呢,IDEA 本身自带对SpringBoot支持的插件,不像Eclipse那样,要用插件还需要从第三方安装, 而且很缓慢 (国外插件源)。 所以本知识点就使用IDEA自带的 SpringBoot插件来开发了。
菜单 -> New -> Project -> Spring Initializer 然后点 Next
输入group,artifact两个地方的参数,其他参数不用修改,然后Next
接着左边选择 Web, 右边只勾选 Web 即可,然后点击Next
项目创建好之后,就自带一个SpringbootApplication, 其被@SpringBootApplication 所标记,表示这个是一个Springboot 应用
新建包
com.text.springboot.web, 然后在其下新建类HelloController.
这个类就是Spring MVC里的一个普通的控制器。
@RestController 是spring4里的新注解,是@ResponseBody和@Controller的缩写。
这个类就是Spring MVC里的一个普通的控制器。
@RestController 是spring4里的新注解,是@ResponseBody和@Controller的缩写。
代码比较复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
package
com.how2java.springboot.web;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RestController;
@RestController
public
class
HelloController {
@RequestMapping
(
"/hello"
)
public
String hello() {
return
"Hello Spring Boot!"
;
}
}
|
http://127.0.0.1:8080/hello
更多实例请访问http://how2j.cn/k/springboot/springboot-mybatis-crud-pagination/1651.html?p=36789