java web 之springboot教程(一)----IDEA构建springboot thymeleaf项目

工具:IDEA intellj

SpringBoot在建立生产中的独立程序上非常简便、只需要一些简便的配置就能运行起来。大致有如下特点:

  1. 创建独立的Spring applications
  2. 能够使用内嵌的Tomcat, Jetty or Undertow,不需要部署war
  3. 提供starter pom来简化maven配置
  4. 自动配置Spring
  5. 提供一些生产环境的特性,比如metrics, health checks and externalized configuration
  6. 绝对没有代码生成和XML配置要求

SpringMVC处理Web请求,Thymeleaf定义Web视图,Spring Data JPA把阅读列表持久化到数据里,thymeleaf为springboot默认配置的模板引擎,默认的模板配置路径为:src/main/resources/templates  ,通过这种方法用html文件来替代jsp,jsp无法实现thymeleaf的很多特性。

1,File ----new----spring initializr,填写好group和artifact

 

 

勾选web

勾选thymeleaf

 完成项目创建。

目录如下:

快速开始:

先看一下pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.cx</groupId>
	<artifactId>springbootdemo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>springbootdemo</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

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


</project>

 这块统一用spring-boot-starter-parent做为parent.

插件是用来运行Springboot的,通常有两种方式可以运行SpringBoot,一种是通过直接运行main方法,另外一种是通过使用下面的插件运行。 

两种方式有差别,一旦项目中需要访问资源的时候就需要通过插件运行,否则无法访问到资源.

整个程序的入口是SpringbootdemoApplication.java:

package com.cx.springbootdemo;

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

@SpringBootApplication
public class SpringbootdemoApplication {

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

只要运行main方法或者插件,就能够正常访问了。

配置详解

@SpringBootApplication 这个注解是一个组合注解,聚合了多个注解的功能。

application.properties 文件详解

整个应用程序的配置文件,SpringBoot自动加载,SpringBoot提供针对各种组件的都可以通过application.properties进行配置,后续再进行详解。  

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值