美文网首页
使用idea搭建SpringBoot

使用idea搭建SpringBoot

作者: 简书小嘉 | 来源:发表于2019-06-13 11:51 被阅读0次

    本文使用idea2018、jdk8、tomcat8.0、mysql、mybatis进行搭建 、作为初学者在这里记录自己搭建springboot的过程。

在这里说明下  使用idea 搭建会省略很多步骤   对比 eclipse  会有很大不同记得注意区分

jdk、maven、tomcat 在idea中如何设置请自行百度

1.使用idea创建一个项目:

    在idea 下面选项 Web中 会有 web选项记得有的勾选上

到此搭建一个空的springboot项目 就成功了

2..进行扩展spring项目

找到 pom.xml 打开

此处便是lib包引用 我们加上以下代码

<dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-thymeleaf</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web-services</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-data-jpa</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <dependency>

            <groupId>org.mybatis.spring.boot</groupId>

            <artifactId>mybatis-spring-boot-starter</artifactId>

            <version>2.0.1</version>

        </dependency>

        <dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

            <scope>runtime</scope>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

            <scope>provided</scope>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-autoconfigure</artifactId>

            <version>2.1.4.RELEASE</version>

        </dependency>

写完后 编译器 在右下角会提示  导入修改  

成功后创建 类 并写返回值进行测试、

然后在启动类上添加注解

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) //忽略数据库配置

在启动类上点击 “播放” 按钮启动项目,并在浏览器中输入http://127.0.0.1:8080/test/getValue

至此我们一个基础的项目就搭建完成了。

3.第一个hollo world

spring boot 集成了很简化的方式进行指定包名

在resources 中新建 templates(html)、static(静态资源css,img等)文件夹

在templates 下新建test 文件 并在test文件夹下新建 index.html

在TestController中添加方法

@RequestMapping("/index")

public void index() {

}

启动项目 在浏览器中输入 http://127.0.0.1:8080/test/index

下一章记录自己 如何完成 mybatis + mysql 并实现部署

相关文章

网友评论

      本文标题:使用idea搭建SpringBoot

      本文链接:https://www.haomeiwen.com/subject/xkcjfctx.html