Spring-boot使用eclipse搭建项目(一)

    开门见山:应用到的技术有spring-boot,mybatis,springmvc,mysql,thymeleaf。

首先给自己的eclipse安装sts,传送门:https://blog.csdn.net/zhen_6137/article/details/79383941

1.创建spring-boot项目

new project找到Spring Starter Project

Spring-boot使用eclipse搭建项目(一)_第1张图片

点击next之后 填写参数

Spring-boot使用eclipse搭建项目(一)_第2张图片

下图可选择依赖,可以跳过

Spring-boot使用eclipse搭建项目(一)_第3张图片

2.创建必要文件及文件夹

finish之后可以看到我们创建的项目,src/main/resources源代码文件夹上右键,选择new->folder。新建以下几个文件夹,static(用于存放静态资源,如js、css或img)templates(用于存放html)

Spring-boot使用eclipse搭建项目(一)_第4张图片

添加依赖,pom.xml文件:



  4.0.0

  com.testBoot
  springboottest
  0.0.1-SNAPSHOT
  jar

  springboottest
  Demo project for Spring Boot

  
    org.springframework.boot
    spring-boot-starter-parent
    2.0.2.RELEASE
     
  

  
    UTF-8
    UTF-8
    1.8
  

  
    
      org.springframework.boot
      spring-boot-starter
    
    
      org.springframework.boot
      spring-boot-starter-test
      test
    
    
    
      org.springframework.boot
      spring-boot-starter-web
    
    
    
      org.springframework.boot
      spring-boot-starter-web-services
    
    
    
      org.springframework.boot
      spring-boot-starter-websocket
    
    
    
      org.springframework.boot
      spring-boot-starter-thymeleaf
    
    
    
      org.springframework.boot
      spring-boot-starter-mail
    
    
    
      mysql
      mysql-connector-java
      runtime
    
    
    
      org.mybatis.spring.boot
      mybatis-spring-boot-starter
      1.3.2
    
    
    
      org.springframework.restdocs
      spring-restdocs-mockmvc
      test
    
    
    
    
    
    
    
      io.springfox
      springfox-swagger2
      2.8.0
    
    
      io.springfox
      springfox-swagger-ui
      2.8.0
    
    
    
      org.springframework.boot
      spring-boot-starter-test
      test
    
    
    
      org.springframework.boot
      spring-boot-devtools
      true 
    
  

    
        springboottest  
          
              
                org.springframework.boot  
                spring-boot-maven-plugin  
              
          
    

使用application.yml代替application.properties

配置文件为:

server:
  port: 8080
  servlet:
    context-path: /boot
  
# =====================数据源配置===========================
spring:
  datasource:
     url: jdbc:mysql://127.0.0.1:3306/boottest?characterEncoding=utf8
     username: root
     password: root
     driver-class-name: com.mysql.jdbc.Driver
# =====================Thymeleaf 配置===========================
  thymeleaf:
    enabled: true  # 是否启用thymeleaf模板解析
    cache: false   # 是否开启模板缓存(建议:开发环境下设置为false,生产环境设置为true)
    check-template-location: true # Check that the templates location exists.
    servlet: 
      content-type: text/html  # 模板的媒体类型设置,默认为text/html
    encoding: UTF-8  # 模板的编码设置,默认UTF-8
    characterEncoding: UTF-8
    #view-names:  # 设置可以被解析的视图,以逗号,分隔
    #excluded-view-names: # 排除不需要被解析视图,以逗号,分隔
    #mode:HTML5 # 模板模式设置,默认为HTML5
    prefix: classpath:/templates/  # 前缀设置,SpringBoot默认模板放置在classpath:/template/目录下
    suffix: .html  # 后缀设置,默认为.html
    #template-resolver-order: # 模板在模板链中被解析的顺序
  jmx:
#    enabled: false
    default-domain: springboottest   
logging:
  path: D:\JavaFiles\logs\spring boot\logs
  level: 
        com.springboottest.dao: DEBUG

图示:

Spring-boot使用eclipse搭建项目(一)_第5张图片

3.测试项目是否可运行

接下来创建controllerhtml测试项目是否可运行:

图示:

Spring-boot使用eclipse搭建项目(一)_第6张图片

IndexController.java代码:

package com.springboottest.web;

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

@Controller
@RequestMapping("/")
public class IndexController {

  @RequestMapping("/")
  public String indexPage(){
  
    return "index";
  }
}

index.html代码:





Insert title here


	

welcome to spring-boot

由于我们安装了sts插件,eclipse可以很方便的启动项目,如图示操作即可:

Spring-boot使用eclipse搭建项目(一)_第7张图片

待启动完毕之后,在浏览器输入http://localhost:8080/boot/地址之后效果:

Spring-boot使用eclipse搭建项目(一)_第8张图片

至此eclipse搭建springboot项目完毕。

在下篇博客将使用thymeleaf、bootstrap实现注册登录。《Spring-boot使用eclipse搭建项目(二)》

你可能感兴趣的:(javaEE)