SpringBoot 入门(一)

来源:互联网 发布:python rang 编辑:程序博客网 时间:2024/06/06 20:28

虽然很菜,可还是想稍微给人指个路,如果你需要的话。
以下内容,仅适合超级大白菜。编译器建议使用Idea。
新建MAVEN项目
1- pom引入jar

         <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>            <version>1.5.3.RELEASE</version>         </dependency> 

2- 打包编译工具

 <build>        <plugins>            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-compiler-plugin</artifactId>                <configuration>                    <source>1.8</source>                    <target>1.8</target>                    <encoding>UTF-8</encoding>                    <skip>true</skip>                </configuration>            </plugin>            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-resources-plugin</artifactId>                <configuration>                    <encoding>UTF-8</encoding>                </configuration>            </plugin>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>                <executions>                    <execution>                        <goals>                            <goal>repackage</goal>                        </goals>                    </execution>                </executions>                <configuration>                    <mainClass>com.revosith.demo.Application</mainClass>                </configuration>            </plugin>        </plugins>    </build>

3- 新建一个启动类

@SpringBootApplication //这个注解 就是核心了public class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}

4 - 来个测试类

@RestControllerpublic class Hello {    @RequestMapping(value= "/hello")    @ResponseBody    public String sayHello(@RequestParam("name")String name){        return "Hello "+name;    }}

5- 启动 Application

6- 哦哦哦 忘记 来个配置了
在resources 下面 新建文件 application.yml
贴进去

server:  context-path: /  port: 8081

7 - 启动Application

8 - http://localhost:8081/hello?name=revosith

9 - github 地址
https://github.com/RevoSith/demo

10 - 不接受批评,批评我,我就
谢谢你!

11 - 好处: install 打个包, 控制台直接 java -jar 你的jar包.jar 就可以启动了

原创粉丝点击