springboot搭建web项目(转)
转:http://blog.csdn.net/linzhiqiang0316/article/details/52589789
这几天一直在研究IDEA上面怎么搭建一个web-mvc的SpringBoot项目,看网上的教程一步步的搭建,可是还是出现一堆的问题。
为了让大家以后少走一些弯路,我在这里分享一下我这几天研究的成果,也希望对大家能有所帮助。
这里先介绍一下各种环境的配置信息:idea2016.2.1 jdk1.8.0_31
因为SpringBoot中是内置tomcat的,所以也就不需要额外的tomcat配置了,现在开始讲如何在idea上面搭建SpringBoot web-mvc项目了
步骤一:在IDEA中新建一个常规的maven项目,具体步骤请看看下面的图示:
通过图上面的几个步骤,一个基本的maven项目就搭建完成了,接下来就是开始搭建SpringBoot中各种配置文件信息了。
步骤二:
1.先复制以下代码到pox.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.example</groupId>
 - <artifactId>demo</artifactId>
 - <version>0.0.1-SNAPSHOT</version>
 - <packagingexample>jar</packagingexample>
 - <name>demo</name>
 - <description>Demo project for Spring Boot</description>
 - <parent>
 - <groupId>org.springframework.boot</groupId>
 - <artifactId>spring-boot-starter-parent</artifactId>
 - <version>1.4.0.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-web</artifactId>
 - </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-starter-thymeleaf</artifactId>
 - </dependency>
 - </dependencies>
 - <build>
 - <plugins>
 - <plugin>
 - <groupId>org.springframework.boot</groupId>
 - <artifactId>spring-boot-maven-plugin</artifactId>
 - </plugin>
 - </plugins>
 - </build>
 - </project>
 
2.点击maven中jar包依赖更新按钮,具体操作看下面图示:
3.配置resources下面的Web资源文件,这里我就配置两个文件,一个是用来存放静态文件夹的static文件,还有一个就是用来存放HTML的资源文件夹templates。
这里需要特别主要的是:static文件中一般存放css,js,image等静态资源文件,而templates文件中一般存放各种HTML文件。而且这两个文件都是默认存在的,路径不需要特别的配置就可以直接引用了。
application.properties是个配置文件,这里面可以配置SpringBoot的相关信息。大家需要注意的是这个文件名千万不要写错,也不要放错位置,不然都不会生效的。
下面看图示案例和代码案例:
csstest.css的代码信息:
- body {
 - padding: 0px;
 - margin: auto;
 - font-family: "黑体", "仿宋", Arial, "Arial Unicode MS", System;
 - background-color: #00F;
 - font-size: 20px;
 - text-align: left;
 - }
 
welcome.html的代码信息:
- <html>
 - <head>
 - <title>Title</title>
 - </head>
 - <link href="css/csstest.css" rel="stylesheet"/>
 - <body>
 - <p>welcome page is login.........</p>
 - </body>
 - </html>
 
application.properties配置文件的代码信息:
- #修改tomcat的默认的端口号,将8080改为8888
 - server.port=8888
 
4.编写SpringBoot中Web-Mvc的控制器和项目启动入口:
DemoApplication.Java具体代码:
- package example;
 - import org.springframework.boot.SpringApplication;
 - import org.springframework.boot.autoconfigure.SpringBootApplication;
 - @SpringBootApplication
 - public class DemoApplication {
 - public static void main(String[] args) {
 - SpringApplication.run(DemoApplication.class, args);
 - }
 - }
 
HelloController.java的具体代码:
- package example;
 - import org.springframework.stereotype.Controller;
 - import org.springframework.web.bind.annotation.RequestMapping;
 - import org.springframework.web.bind.annotation.ResponseBody;
 - import java.util.HashMap;
 - import java.util.Map;
 - @Controller
 - public class HelloController {
 - @RequestMapping("/index")
 - public String index(){
 - return "welcome";
 - }
 - }
 
这样SpringBoot的Web-mvc项目就已经搭建成功了,具体步骤就是这样的。
springboot搭建web项目(转)的更多相关文章
- springBoot 搭建web项目(前后端分离,附项目源代码地址)
		
springBoot 搭建web项目(前后端分离,附项目源代码地址) 概述 该项目包含springBoot-example-ui 和 springBoot-example,分别为前端与后端,前后端 ...
 - 使用SpringBoot搭建Web项目
		
序言 从简入深的使用SpringBoot搭建一个Web项目,同时也包括一些小的问题.第一篇博文是以较为简单的方式完成一个可以连接数据库的Springboot web程序.之前自己学习的时候看网上的教程 ...
 - Springboot搭建web项目
		
最近因为项目需要接触了springboot,然后被其快速零配置的特点惊呆了.关于springboot相关的介绍我就不赘述了,大家自行百度google. 一.pom配置 首先,建立一个maven项目,修 ...
 - springboot搭建web项目与使用配置文件
		
目录 一.准备工作 二.创建基础web项目 1. maven配置 2.创建maven项目.配置pom.xml为web基础项目 3.编写启动类 4.使用maven打包 5.使用命令java -jar x ...
 - Spring-Boot快速搭建web项目详细总结
		
最近在学习Spring Boot 相关的技术,刚接触就有种相见恨晚的感觉,因为用spring boot进行项目的搭建是在太方便了,我们往往只需要很简单的几步,便可完成一个spring MVC项目的搭建 ...
 - 使用idea+springboot+Mybatis搭建web项目
		
使用idea+springboot+Mybatis搭建web项目 springboot的优势之一就是快速搭建项目,省去了自己导入jar包和配置xml的时间,使用非常方便. 1.创建项目project, ...
 - Spring Boot搭建Web项目常用功能
		
搭建WEB项目过程中,哪些点需要注意: 1.技术选型: 前端:freemarker.vue 后端:spring boot.spring mvc 2.如何包装返回统一结构结果数据? 首先要弄清楚为什么要 ...
 - 基于springboot的web项目最佳实践
		
springboot 可以说是现在做javaweb开发最火的技术,我在基于springboot搭建项目的过程中,踩过不少坑,发现整合框架时并非仅仅引入starter 那么简单. 要做到简单,易用,扩展 ...
 - 【maven】 在  MyEcplise上使用maven搭建Web项目
		
二.在My Ecplise上使用Maven搭建Web项目 1.新建一个maven项目 2.create一个简单的骨架 3.就像在ecplise中一样设置项目的以下配置 4.新创建的项目结构如下 ...
 
随机推荐
- Python自动化运维——文件内容差异对比
			
Infi-chu: http://www.cnblogs.com/Infi-chu/ 模块:difflib 安装:Python版本大于等于2.3系统自带 功能:对比文本之间的差异,而且支持输出可读性比 ...
 - PHP.41-TP框架商城应用实例-后台16-商品属性2-AJAX添加、删除
			
添加商品属性 思路:根据[后台15]类型表{id,type_name}与属性表{id,attr_name,attr_type,attr_option_values,type_id} 1.建表商品属性 ...
 - Moodle 3.4中添加小组、大组、群
			
Moodle在高中应用时经常要用到年级.班级和小组,我们可以用群.大组.小组来代替. 小组设置:网站首页-->现有课程-->右上角的设置按钮-->更多-->用户-->小组 ...
 - Git 查看远程分支、本地分支、删除本地分支及远程分支
			
1. 删除本地分支: git branch -d branchName 2. 删除远程分支: // 方法一:将删除的本地分支推到远程(要删除的远程分支在本地有映射) git push origin : ...
 - Android Stadio 指定文件打开类型
			
我们项目里面,有一个文件,叫做aaa.meta. 这个只是一个配置文件,里面是txt. 但是Android Stadio 不识别.怎么办? 设置如下图: 首先,打开Android stadio 的设置 ...
 - (干货分享)mac  python+appium环境搭建
			
因为mac本自带python2.x(不建议卸载,因为本本本身有很多依赖与此),所以装python3的过程极其坎坷,勉强装好后也总是各种报错.这次装appium环境,直接把原来的python3卸了,用h ...
 - cocos2d-x 键盘和鼠标事件
			
出了菜单可以响应用户事件外,cocos2d中的层(Layer)也可以响应事件.层能够自动响应窗口事件,这些事件主要是键盘和鼠标事件,cocos2d中事件处理是通过Pyglet的事件处理完成的. 1.键 ...
 - 12-Mysql数据库----多表查询
			
本节重点: 多表连接查询 符合条件连接查询 子查询 准备工作:准备两张表,部门表(department).员工表(employee) create table department( id int, ...
 - LeetCode - 38. Count and Say(36ms)
			
The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 ...
 - 关于iframe的使用 以及自适应页面高度
			
1. <a href="port" target="frame_view">港口资料</a> <iframe id="e ...