创建第一个springboot项目

1.创建第一个springboot项目

环境:jdk1.8,idea2018

1.1 创建工程的时候选择Spring Initializr

在这里插入图片描述

1.2 填写项目的基本信息

在这里插入图片描述

1.3 选择项目中需要的模块(web、sql、aop等),在创建工程的时候向导会联网自动将这些模块依赖的jar包引入,一定要联网

在这里插入图片描述

1.4 完成创建Finsh

在这里插入图片描述

第一次创建可能会慢,maven建议改成阿里镜像,修改maven安装位置下的config的setting.xml文件

<mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
  </mirrors>

生成的主程序:

@SpringBootApplication
public class Springboot01HelloworldApplication {

    public static void main(String[] args) {
        SpringApplication.run(Springboot01HelloworldApplication.class, args);
    }

}

编写controller类:

@Controller
public class HelloController {
    @RequestMapping("hello")
    @ResponseBody
    public  String hello(){
        return "hello spring";
    }
}
1.5 执行主程序

若出现tomcat登录页面,账号为user,密码为控制台输出的一段字符串

自动生成的resources目录下有两个文件夹和一个配置文件

在这里插入图片描述

  • static:保存所有的静态资源(JS、CSS、图片等)

  • templates:保存所有的模板页面,SpringBoot默认采用JAR包并使用嵌入式的tomcat,默认是不支持JSP页面的,需要使用模板引擎(freemarker、thymeleaf)

  • application.properties:SpringBoot应用的配置文件,可在该配置文件中修改默认配置(比如应用的端口)

在这里插入图片描述

成功创建!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值