一、快速建立springboot项目css
1.一、使用spring官方SPRING INITIALIZR工具能够快速建立springboot项目。IDEA开发工具也集成了spring initializr工具java
1.二、maven项目目录结构spring
project maven浏览器
|--java目录结构(保存全部后台java代码)springboot
|----com.company.projectname.controllerapp
|----com.company.projectname.servicemaven
|----com.company.projectname.daoide
|--resource目录结构spring-boot
|----static:保存全部的静态资源(js,css,image)工具
|----template:保存全部的模板页面
|----application.properties:spring应用配置文件
二、SpringBootApplication注解
/** *SpringBootApplication注解,应用的入口,能够启动应用 */ @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class,args); } }
三、springboot应用打包运行
打包:springboot maven插件,能够将应用打包成一个可执行jar。将下面配置在pom.xml,执行idea maven:Lifecycle -> package
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
controller编写:
/** * RestController = Controller + ResponseBody * ResponseBody :方法返回的数据直接给浏览器 */ @RestController public class HelloController { @RequestMapping("/hello") public String hello(){ return "hello world!"; } }
运行:java -jar spring-boot-helloword-1.0-SNAPSHOT.jar
访问:localhost:8080/helloworld