Spring-boot 的使用 方便了Spring 项目的管理和维护
1 建立基本项目:?https://start.spring.io/?
?
??
?
可以选择 web, jpa ,mysql . ?点击 Genarate Project 下载 .
?
2 导入 Eclipse 项目?
? ?解压下载的ZIp 文件到目录, 打开 Eclipse 选择 Import Existing Maven Project?
? ?
?
? ? 点击 Next 选择 刚才解压的目录,导入就可以了。
?
3 目录说明:
? ?
?
?static 缺省的静态文件目录。
?templates 是模板目录。 项目缺省使用 ?thymeleaf 模板技术
?
3 ?运行:?
? ? ?找到 DemoApplication ?点击右键,Run as Application 就可以了。 缺省地使用Tomcat ,大家可以使用
? ?http://127.0.0.1:8080/ ? 访问
4 去掉Tomcat ,加入Jetty?
? ? ??
?
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>
?
?
5 加入 thymeleaf?
? ??
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
?6 加入 Mysql ,和 bibernate 支持
?
? ??
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>
?修改 application.properties 在 resources 目录下。
?
? ??
? ??
?
完整的连接数据库测试:
?
1 建立数据库 ,Mysql 的。? ?
?测试路径: ?http://127.0.0.1:8080/greeting/test
?
? ? ? ? ?
?
完整项目代码 ?GitHub 下载:
?
? ? ?https://github.com/guanry/wmshop.git
?
?
?
?
原文:http://guanxi.iteye.com/blog/2272620