Springboot 写一个简单的hello world并且打包成jar包

  在IDEA中初始化一个Springboot项目。

  

  在main函数里面写好程序入口:

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
    @SpringBootApplication
    public class Demo4Application {
        public static void main(String[] args) {
            SpringApplication.run(Demo4Application.class, args);
        }
    }

  下面利用@controller和@RequestMapping来实现浏览器输出hello的效果。

  

package com.example.demo;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class sController {
    @ResponseBody
    @RequestMapping("/hello")
    public String hello()
    {
        return "hello,chenyanzhou";
    }

}

  下面进行编译和运行:

   可以发现自动在Tomcat服务器部署完成,登录8080端口查看是否成功——

  

下面进行jar文件的打包——

点击Run Maven Build,成功以后会显示Build Success。

 在CMD中进行验证——

 

运行成功。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值