java坦克大战编写打包jar_傻瓜式学JAVA---springboot入门

傻瓜式学JAVA---springboot入门


功能:浏览器发送hello请求,服务器接收并处理,响应hello spring字符串

一、创建Maven工程

1cb92e5934dfc935baaea284da307a24.png

创建项目:springboot_hello

da90d6b4fc0c925bf03dcb4e099c7c9b.png

3d49fe7a5e0880b5c897118e41b1b658.png

选择自佛那个导入jar包

54ecf08ad752b226d6de50b1ad372ab1.png

选择设置Maven配置

d6d741c1eab7b9925b2196f88fd70436.png

修改Maven配置

43a106164dbafd1b5e13df9db3e7cd1d.png

二、导入Spring boot相关依赖

使用Maven创建项目,需要导入依赖:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.2.1.RELEASE</version>
</parent>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependency>

ab1baa1771612e0706c860e297499439.png

三、编写主程序

1.创建主程序

8d1f2a609c00f7fc4cd3784558fd528e.png
package com.learn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//SpringBootApplication标注主程序类
@SpringBootApplication
public class HelloSpringMainApplication {
    public static void main(String[] args) {
        //Spring 应用启动
        SpringApplication.run(HelloSpringMainApplication.class,args);
    }
}

四、编写相关Controller、Service

package com.learn.com.learn.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "hello springboot";
    }

}

五、启动springboot项目

5c7fa75f317822233f3e6d67d404f4c8.png

项目启动端口为 8080

网页访问路径:http://localhost:8080/hello

7a5fe03735cf2e11d04cdea36dbf1c17.png

六、应用打包

加入依赖:将应用打包成一个可执行的jar包

<build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>

afbc824c9baf9c0a4abecfd35128df62.png

七、运行程序包

运行JAR包:

命令:Java -jar springboot_hello-1.0-SNAPSHOT.jar

e50ddddebb12c6f8fd8aaab1c77eb327.png

八、使用IDEA自动创建Springboot项目

d36c6eb9ca760cbf37ae6c20b02fe8ce.png

4ef1c6b8865c7b28cd767f08c89462f2.png

e773acce6ab2b2fa39c4c392ad775ae8.png

8a11983b2bbbcb326765a4f5a273fed1.png

ee9d9aeb20d890e94e105a1e07bc8297.png

编写Controller

package com.learn.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class hello {
    @ResponseBody
    @RequestMapping("/hd")
    public String Hello(){
        return "hello Spriongboot";
    }
}

启动运行:

520e932b63e49bfea14f053be2d2c8cc.png

欢迎关注公众号---后台服务器开发,更多精彩等你来看~


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值