赞
踩
下载eclipse(不知道在哪下载就百度吧,在未来离不开搜索引擎的社会下,你即便学不会开发只是知道如何找资料_!)
下载JDK1.8
下载Maven最新版本
<localRepository>F://Development//repository</localRepository>
指向本地建立的目录,建议将repository目录建在Development下,将来可以直接复制走。
进入eclipse
菜单->window->Preferences
add->选择Maven的目录
Global Settings->选择Maven目录下conf的settings.xml
User Settings同上
com.compayname.projectnamesrc/main/java #java代码src/main/test #junit测试代码src/main/resource #所以资源和页面文件src/main/resource/templates #页面文件src/main/resource/static #静态页面文件pom.xml文件<!-- 公共spring-boot配置,下面依赖jar文件不用在写版本号 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <!-- spring boot 1.x最后稳定版本 --> <version>1.4.1.RELEASE</version> <!-- 表示父模块pom的相对路径,这里没有值 --> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>> <java.version>1.8</java.version> <!-- set thymeleaf version --> <thymeleaf.version>3.0.0.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version> </properties> <dependencies> <!-- web --> <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> <!-- 只在test测试里面运行 --> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies>
创建包com.mytest.simple.springboot
创建类Application
package com.mytest.simple.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Spring Boot 应用启动类 * * @author Administrator * */ // Spring Boot应用标识 @SpringBootApplication public class Application { public static void main(String[] args) { // TODO Auto-generated method stub SpringApplication.run(Application.class, args); } }
创建包com.mytest.simple.springboot.controller
创建类HelloController
package com.mytest.simple.springboot.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; /** * 第一个简单的例子HelloController * * @author administrator **/ @Controller public class HelloController { @GetMapping(value = "/hello") public String hello(Model model) { String name = "jiangbei"; model.addAttribute("name", name); return "hello"; } }
创建hello.html页面
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link
href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css"
rel="stylesheet">
</head>
<body>
<!--/*@thymesVar id="name" type="java.lang.String"*/-->
<p th:text="'Hello!, ' + ${name} + '!'">3333</p>
</body>
</html>
在src/main/resource目录下创建文件application.yml文件
# 开发环境配置 server: # 服务端口 port: 80 servlet: # 项目contextPath context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # tomcat最大线程数,默认为200 max-threads: 20 # Tomcat启动初始化的线程数,默认值25 min-spare-threads: 20 # Spring配置 spring: # 模板引擎 thymeleaf: mode: HTML encoding: utf-8 # 禁用缓存 cache: false
配置文件中定义了http端口是80
选择Application,右键->Run as->Java Application
OK
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。