标签:plugins build control 配置文件 nbsp [] public boot static
1、快速创建springboot项目
1.1、使用spring官方SPRING INITIALIZR工具可以快速创建springboot项目。IDEA开发工具也集成了spring initializr工具
1.2、maven项目目录结构
project maven
|--java目录结构(保存所有后台java代码)
|----com.company.projectname.controller
|----com.company.projectname.service
|----com.company.projectname.dao
|--resource目录结构
|----static:保存所有的静态资源(js,css,image)
|----template:保存所有的模板页面
|----application.properties:spring应用配置文件
2、SpringBootApplication注解
/**
*SpringBootApplication注解,应用的入口,可以启动应用
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
3、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
标签:plugins build control 配置文件 nbsp [] public boot static
原文地址:https://www.cnblogs.com/chenweichu/p/9998188.html