v阅读目录
vSpring Boot概念
v搭建Spring Boot
v博客总结
v博客前言
最近公司有一个内部比赛(黑客马拉松),报名参加了这么一个赛事,在准备参赛作品的同时,由于参赛服务器需要自己搭建且比赛产生的代码不能外泄的,所以借着这个机会,本地先写了个测试的demo,来把tomcat部署相关的知识从0到1重新捋一遍。就当备忘录了。
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。
回到顶部
vSpring Boot概念
从最根本上来讲,Spring Boot就是一些库的集合,它能够被任意项目的构建系统所使用。简便起见,该框架也提供了命令行界面,它可以用来运行和测试Boot应用。框架的发布版本,包括集成的CLI(命令行界面),可以在Spring仓库中手动下载和安装。
创建独立的Spring应用程序
嵌入的Tomcat,无需部署WAR文件
简化Maven配置
自动配置Spring
提供生产就绪型功能,如指标,健康检查和外部配置
绝对没有代码生成并且对XML也没有配置要求
回到顶部
v搭建Spring Boot
1. 生成模板
可以在官网https://start.spring.io/生成spring boot的模板。如下图
详解intellij idea搭建Spring Boot
然后用idea导入生成的模板,导入有疑问的可以看我另外一篇文章
详解intellij idea搭建Spring Boot
2. 创建Controller
详解intellij idea搭建Spring Boot
3. 运行项目
添加注解 @ComponentScan(注解详情点这里) 然后运行
详解intellij idea搭建Spring Boot
在看到"Compilation completed successfully in 3s 676ms"消息之后,打开任意浏览器,输入 http://localhost:8080/index 即可查看效果,如下图
详解intellij idea搭建Spring Boot
4. 接入mybatis
MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。
在项目对象模型pom.xml中插入mybatis的配置
复制代码
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.1.1
mysql
mysql-connector-java
5.1.30
复制代码
创建数据库以及user表
复制代码
use zuche;
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`age` int(10) NOT NULL,
`phone` bigint NOT NULL,
`email` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
insert into users values(1,'赵',23,158,'3658561548@qq.com');
insert into users values(2,'钱',27,136,'3658561548@126.com');
insert into users values(3,'孙',31,159,'3658561548@163.com');
insert into users values(4,'李',35,130,'3658561548@sina.com'
复制代码
分别创建三个包,分别是dao/pojo/service, 目录如下
详解intellij idea搭建Spring Boot
添加User:
详解intellij idea搭建Spring Boot View Code
添加UserMapper:
详解intellij idea搭建Spring Boot View Code
添加UserService:
详解intellij idea搭建Spring Boot View Code
添加UserServiceImpl
详解intellij idea搭建Spring Boot View Code
controller添加API方法
详解intellij idea搭建Spring Boot View Code
修改租车ZucheApplication
详解intellij idea搭建Spring Boot View Code
添加数据库连接相关配置,application.properties
复制代码
spring.datasource.url=jdbc:mysql://localhost:3306/zuche
spring.datasource.username=toutou
spring.datasource.password=*******
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
复制代码
按如下提示运行
详解intellij idea搭建Spring Boot
浏览器输入得到效果:
详解intellij idea搭建Spring Boot
回到顶部
v博客总结
系统故障常常都是不可预测且难以避免的,因此作为系统设计师的我们,必须要提前预设各种措施,以应对随时可能的系统风险。
您可以考虑给头头来个小小的打赏以资鼓励,您的肯定将是我最大的动力。thx.
微信打赏
微信账号 i7toutou
支付宝打赏
支付宝账号 datou431@qq.com
作 者:请叫我头头哥
出 处:http://www.cnblogs.com/toutou/
关于作者:专注于基础平台的项目开发。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力! https://www.cnblogs.com/toutou/p/9650939.html