
spring-boot
文章平均质量分 51
没事偷着乐琅
书中自有黄金屋,书中自有颜如玉。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
spring boot 启动打开网页
代码如下:public static void main(String[] args) throws IOException, SQLException { ConfigurableApplicationContext application = SpringApplication.run(ServiceApplication.class, args); String port = application.getEnvironment().getProperty("server.port"原创 2021-03-23 19:33:14 · 1019 阅读 · 0 评论 -
spring boot配置 druid
第一步spring: profiles: active: dev datasource: username: root password: url: jdbc:mysql://localhost:3306/zll?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTi...原创 2020-02-01 18:02:43 · 393 阅读 · 1 评论 -
spring boot 初始化 sql脚本
在spring boot 启动时,执行数据库脚本第一步:将 sql 脚本保存到 resource 目录下任意位置。第二步。配置数据源和 脚本位置spring: profiles: active: dev datasource: username: root password: url: jdbc:mysql://localhost:3306/zll?...原创 2020-01-30 19:22:03 · 1185 阅读 · 1 评论 -
spring boot 分页 利用 mybaits plus
mybaits + plus <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> ...原创 2019-11-23 16:58:20 · 249 阅读 · 0 评论 -
spring boot 常用功能
环境切换两种方式:一、spring: profiles: active: one ---spring: profiles: oneserver: port: 80---spring: profiles: twoserver: port: 81第二种:application-{profile}.yml例如在 application.yml...原创 2019-10-22 23:20:28 · 392 阅读 · 0 评论 -
spring boot 一 HelloWorld
1、下载 intellij 安装。 2、直接使用Spring Initializr创建Springboot 注意 Project SDK 需要配置 jdk然后一路 next: 勾选 Web Web就可以了。创建完成后 ,maven开始 下载相关的 jar文件,根据网速可能会下载 1个小时左右,完成后,3、完成后,在 demo目录下 创建一个 HelloController 文件。packa原创 2017-11-03 14:11:44 · 292 阅读 · 0 评论 -
spring boot 二 集成 FastJson
1、在 pom.xml 导包 (必须高于 1.2.10 版本) <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependency>2原创 2017-11-03 13:56:56 · 815 阅读 · 0 评论 -
Spring Boot 三 热部署 devtools
Sprint-boot-devtools 是一个为开发者服务的一个模块,其中最重要的功能就是热部署。其原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个ClassLoader加载会更改的类,称为 restart ClassLoader工作方式,ClassLoader检测 应用的 class文件 如果有改变就会重新加载这些改变的 clas原创 2017-11-03 22:21:27 · 240 阅读 · 0 评论 -
Spring boot 四 JPA Hibernate
1、在pom.xml 中添加 依赖包: 2、编写 application.properties 3、创建 实体映射对象 4、创建 对象 Repository 接口 5、创建 对象服务 6、创建 对象 Controller1、在pom.xml 中添加 依赖包: <dependency> <groupId>org.springframework.boo原创 2017-11-04 23:25:36 · 824 阅读 · 0 评论 -
Spring boot 五 jdbcTemplate
上一节我们讲了 spring-boot-jpa 框架 spring-boot-jpa:在原有 hibernate 框架的基础上在做继续包装,简化。 这节我们介绍 如何在 Spring boot 中使用模板技术。 这里最简单的 jdbcTemplate 使用:1、在pom.xml 添加依赖包。 2、创建实体对象 例如 Person: 3、创建数据处理层 PersonDao. 4、创建业原创 2017-11-06 19:26:41 · 342 阅读 · 0 评论 -
Spring boot 六 集成 MyBatis
spring boot 集成MyBatis 非常简单:1、添加依赖包。mysql驱动 mybatis驱动(必须大于 1.1.1版本) 2、添加 application.properties 配置。 3、在 Application.main 类 添加 @MapperScan(com.zll.*) 4、添加实体对象 Student 5、编写Student数据映射对象 StudentMapp原创 2017-11-07 10:26:44 · 392 阅读 · 0 评论 -
Spring boot 八 service 配置
1、在resource文件夹 的 application.properties 添加#spring boot 端口设置server.port=8081#spring boot 默认的 context-pathserver.context-path= /test测试路径: 127.0.0.1:8081/test/mybaits/selectAll原创 2017-11-07 22:59:28 · 901 阅读 · 0 评论 -
Spring boot 九 集成 FreeMark
Spring集成freeMark也非常简单: 1、pom中加入依赖包。 2、配置 application.properties.(可以啥都不写使用默认的配置就行) 3、在resource目录下创建 templates 包存放 ftl 模板 4、创建 helloftl.html ,然后将 .html 后缀修改为 .ftl.编辑内容 5、创建 HelloFreeMarkController 编原创 2017-11-08 10:41:53 · 439 阅读 · 0 评论 -
Spring boot 十 定时任务
Spring Boot 定时任务,直接创建 定时类。 添加 注解就可以完成定时任务。“` @Configuration @EnableScheduling public class TestTask {@Scheduled(cron = "0/5 * * * * ?")private void test1(){ System.out.println("Test 每5秒我就会出现原创 2017-11-08 21:22:35 · 328 阅读 · 0 评论 -
Spring boot 十一 interceptor(拦截器)
第一步: 编写拦截器:(com.zll.demo.intercepter.MyInterceptor )/** * 方法流程 例如 访问 http//127.0.0.1:8080/hello * 执行顺序 * 1、preHandle * 2、hellorController * 2、postHandle * 3、视图渲染 * 4、afterCompletion */public原创 2017-11-15 12:50:49 · 391 阅读 · 0 评论 -
spring boot 十二 thymeleaf
spring boot 集成 thymeleaf 非常简单。第一步,导入包。第二步,编写controller第三步。配置。properties (thymeleaf 属于springboot 指定模板,基本使用默认配置不会改动)第四步。创建 html 导入thymeleaf下面直接看demo:第一步,导入包。<!--thymeleaf 集成 包--> <de...原创 2019-03-23 22:48:26 · 160 阅读 · 0 评论 -
Spring boot 十二 CommandLineRuner
第一步: com.zll.demo.command.CommandRun @Component@Order(1)//如果有多个 值小的有限执行(非必要)public class CommandRun implements CommandLineRunner { @Override public void run(String... agrs) throws Exception原创 2017-11-15 13:03:07 · 273 阅读 · 0 评论 -
Spring boot 十三 读取 环境变量
实现 EnvironmentAware setEnvironment()方法 即可 (注意) 不管配置在哪里,启动服务器是,就会执行该方法。 可以单独配置,也可以配置在 其他类中。方法一。 com.zll.demo.config.MyEnvironment @Configurationpublic class MyEnvironment implements EnvironmentAwar原创 2017-11-15 13:15:06 · 3846 阅读 · 0 评论 -
Spring boot 十四 读取 .properties 配置
第一种 读取 application.properties 配置文件。 第二种 读取自定义的 xxx .properties 配置文件。第一种 读取 application.properties 配置文件。 1、在application.properties 中添加 要读取的配置:hello = hello world2、在需要读取的地方 添加 (@Value(“${hello}”))@原创 2017-11-15 13:44:43 · 287 阅读 · 0 评论 -
spring boot 十五 (servlet)
虽然 spring boot 中 直接使用servlet 实现的地方越来越少了,但是spring boot 依然提供了两种方式:方法一 (基于 spring boot @WebServlet 注解扫描):(记得不能要super.doGet()和super.doPost 否则会报错)@WebServlet(name = "helloServlet", urlPatterns = "/hell...原创 2019-03-12 15:58:59 · 444 阅读 · 1 评论 -
spring boot 十六 filter
filter 拦截器 是基于 java web 相对宇哥 spring boot 的 intercepter 要更重一下,执行顺序在 interceptor之前 。是否方式有两种 和 spring boot 实现servlet 方式类似:方法一:(通过注解实现 @WebFilter)@WebFilter(urlPatterns = "/*")public class HelloFilt...原创 2019-03-12 16:16:36 · 209 阅读 · 0 评论 -
spring boot 十七 redis(入门)
spring boot 集成redis 非常简单。但是要用好还是有点难度。入门:pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</arti...原创 2019-03-12 23:39:01 · 266 阅读 · 0 评论 -
spring boot 十八 redis (AOP 方式)
在上一章的基础上 。升级代码。第一步加入 AOP <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> ...原创 2019-03-13 00:02:23 · 692 阅读 · 0 评论 -
spring boot 十九 spring cache + redis
spring boot cache 是spring 提供的一套缓存统计接口只需要用这一套 缓存接口,下面可以兼容 redis ehcahe 实现对缓存的解耦。spring boot cache 集成 redis 非常简单:第一 导入 依赖 <dependency> <groupId>org.springframework.boot</groupId&g...原创 2019-04-21 17:09:17 · 301 阅读 · 0 评论 -
spring boot 二十 redis 分布式 锁
分布式锁 要解决的问题就是高并发时导致的数据重复读取。为了保证数据的 一致性,在单服务中我们使用 synchronize 在分布式服务中,这个显然是不行的,为了解决这个问题,我们一般使用 Redis的分布式锁 或 ZooKeeper的分布式锁。直接上代码:<dependency> <groupId>redis.clients</groupId> ...原创 2019-03-13 16:45:04 · 521 阅读 · 1 评论 -
spring boot 二十一 集成 jsp
第一步加依赖,:配路径 <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency&...原创 2019-03-22 11:57:09 · 108 阅读 · 0 评论 -
spring boot 二十二 打 war jar 包
打jar 包找到maven 工具 使用 点击 package 或者 install 都可以进行打包。查看 pom 的 是否是 jar<packaging>jar </packaging>如果涉及到 jsp 项目 需要修改 maven 插件版本到 1.4.2.RELEASE 其他本部有 bug 打包的jsp 文件找不到。该版本就没有问题。 ...原创 2019-03-22 13:54:31 · 120 阅读 · 0 评论 -
spring boot 二十三 (ActiveMQ 一 ) 下载、安装、配置
ActiveMQ 是apache 旗下的消息中间件产品,它实现了JMS的接口 。JMS是 javaee 定义的消息传送的规范和标准。并没有真正的实现,只是一组接口。下载官网下载路径 :http://activemq.apache.org/找不到哪里下的点这里:http://activemq.apache.org/download-archives.html注意:数字大的就是新版本。5.9...原创 2019-03-26 12:25:22 · 181 阅读 · 0 评论 -
spring boot 二十四 (ActiveMQ 二 )集成 spring boot
ActiveMQ 主要有两种模式:1、点对点(Point-to-Potin) : 消息队列模式2、发布/订阅 (Publish/Subcribe):广播模式消息接收又分为两种1、同步接收消息 : 接收者阻塞式的,会有一个线程一直等待接收消息。2、异步接收消息:监听者模式,有消息时被调用,没消息时,线程会处理别的业务。集成 spring boot 有两种方式。一种完全注解,一种基于con...原创 2019-03-26 16:06:27 · 180 阅读 · 0 评论 -
spring boot 教程
spring boot 常用功能spring boot 一 HelloWorldspring boot 二 集成 FastJsonSpring Boot 三 热部署 devtoolsSpring boot 四 JPA HibernateSpring boot 五 jdbcTemplateSpring boot 六 集成 MyBatisSpring boot 七 全局异常处理Spri...原创 2019-10-25 21:36:12 · 171 阅读 · 0 评论 -
spring boot 二十五 @Configuration注解
在spring boot @Configuration注解 替代 原有的 xxxx.xml 配置。这里以 ActiveMQ 为例:(演示代码,不保证能运行起来。)我们将 spring 。xml 方式的配置 该为 spring boot中 注解方式的配置:xml 如下:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="...原创 2019-03-26 17:24:16 · 2773 阅读 · 0 评论 -
spring boot 二十六 (mybatis 实现多数据源 轮询配置)
源码地址:https://gitee.com/leonzhang2013/mybaits__multiple_data_sources实现原理:关键点一 (去掉spring boot 默认的mybatis 自动配置)spring boot 集成 mybatis 内部默配置只能使用 单实例的数据源。但是在实现多数据源时。不能使用 默认的配置,首先要去掉spring boot 默认的mybat...原创 2019-03-31 23:45:09 · 939 阅读 · 0 评论 -
Spring boot 七 全局异常处理
为了让网站更加的友好,在程序出错时,给客户一个友好的界面。 就需要全局统一异常处理界面Spring boot 全局异常捕获非常简单。 创建一个实体类,在类和方法上加上注解,OK@ControllerAdvicepublic class GlobalExceptionHandler { /*如果返回字符串*/ @ExceptionHandler(Exception.class)原创 2017-11-07 12:39:40 · 344 阅读 · 0 评论