Spring Boot

springboot(8)springboot整合mybatis

我是研究僧i 提交于 2020-12-07 05:43:20
1、使用starter, maven仓库地址:http://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter 2、加入依赖(可以用 http://start.spring.io/ 下载) <!-- 引入starter--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> <scope>runtime</scope> </dependency> <!-- MySQL的JDBC驱动包 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- 引入第三方数据源 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.6</version> <

SpringBoot(十七)_springboot跨域处理

北慕城南 提交于 2020-12-07 01:40:29
本文转自: Vi的技术博客 什么是跨域 首先,我们需要了解一下一个URL是怎么组成的: // 协议 + 域名(子域名 + 主域名) + 端口号 + 资源地址 http: + // + www.baidu.com + :8080/ 只要协议,子域名,主域名,端口号这四项组成部分中有一项不同,就可以认为是不同的域,不同的域之间互相访问资源,就被称之为跨域。 随着前后端分离开发的越来越普及,会经常遇到跨域的问题,当我们在浏览器中看到这样的错误时,就需要意识到遇到了跨域: XMLHttpRequest cannot load http://目标地址No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://当前页面地址' is therefore not allowed access. 解决跨域的几种方案 首先,我们使用vue-cli来快速构建一个前端项目,然后使用axios来向后台发送ajax请求。然后在控制台中打印出返回信息。这里就不再多做赘述,后面我会单独写一篇文章来讲一下如何使用vue-cli快速创建一个vue项目。 这里不再讲解使用jsonp的方式来解决跨域,因为jsonp方式只能通过get请求方式来传递参数,而且有一些不便之处。

SpringBoot 引入本地或第三方Jar包

隐身守侯 提交于 2020-12-07 00:53:42
在开发过程中,我们会遇到一些Maven仓库没有的Jar包的情况,比如公司其他团队开发的Jar包等。这时我们就不能通过Pom文件引入。这里我们使用hutool Jar为例。 一、使用Maven命令把Jar包添加到本地仓库 (1)执行maven命令,把Jar添加到本地。 mvn install:install-file -Dfile=/Users/gongzhiqiang/Documents/JavaWeb/Jar/hutool-all-5.5.2.jar -DgroupId=com.piao -DartifactId=my-hutool -Dversion=1.0 -Dpackaging=jar -Dfile jar的文件路径 -DgroupId 设置包名,可以自定义 -DartifactId 设置模块名,可以自定义 -Dversion 设置版本,可以自定义 -Dpackaging 设置包的类型 看到这个界面我们就成功了,然后只需要我们在项目里引用即可 (2)pom文件添加依赖。如下图: <dependency> <groupId>com.piao</groupId> <artifactId>my-hutool</artifactId> <version>1.0</version> </dependency> 二、把Jar放入项目中添加依赖 (1)在src目录添加一个lib文件夹

springboot Redis 布隆过滤器

℡╲_俬逩灬. 提交于 2020-12-06 19:53:35
一、布隆的定义是什么? 布隆过滤器(英语:Bloom Filter)是1970年由布隆提出的。它实际上是一个很长的二进制向量和一系列随机映射函数。布隆过滤器可以 用于检索一个元素是否在一个集合中。它的优点是空间效率和查询时间都远远超过一般的算法,缺点是有一定的误识别率和删除困难。 Bloom Filter(BF)是一种空间效率很高的随机数据结构,它利用位数组很简洁地表示一个集合,并能判断一个元素是否属于这个集合。 它是一个判断元素是否存在集合的快速的概率算法。Bloom Filter有可能会出现错误判断,但不会漏掉判断。也就是Bloom Filter判断元 素不再集合,那肯定不在。如果判断元素存在集合中,有一定的概率判断错误。因此,Bloom Filter”不适合那些“零错误的应用场合。 而在能容忍低错误率的应用场合下,Bloom Filter比其他常见的算法(如hash,折半查找)极大节省了空间。 二、布隆的原理是什么 布隆过滤器的原理是,当一个元素被加入集合时,通过K个散列函数将这个元素映射成一个位数组中的K个点,把它们置为1。检索时,我 们只要看看这些点是不是都是1就(大约)知道集合中有没有它了:如果这些点有任何一个0,则被检元素一定不在;如果都是1,则被检 元素很可能在。这就是布隆过滤器的基本思想。 Bloom Filter跟单哈希函数Bit-Map不同之处在于:Bloom

关于gradle与maven对springboot项目的配置文件加载异同

China☆狼群 提交于 2020-12-06 18:54:42
先说下缘由吧,由于年后跳槽换了家公司,构建项目工具也有maven改成gradle了,所以在搭建框架进行开发打包过程中难免会遇到一些意想不到的问题。 本文简述下打包扫描加载配置文件的异同吧。 maven打包加载配置文件的配置是在pom文件中配置: 1 <resources> 2 <resource> 3 <directory>src/main/resources</directory> 4 <filtering> false </filtering> 5 <includes> 6 <include>** /* .*</include> 7 </includes> 8 </resource> 9 10 <resource> 11 <directory>src/main/resources</directory> 12 <filtering>true</filtering> 13 <excludes> 14 <exclude>* */ *.woff</exclude> 15 <exclude>** /* .ttf</exclude> 16 <exclude>* */ *.svg</exclude> 17 <exclude>** /* .eot</exclude> 18 </excludes> 19 </resource> 20 21 <resource> 22 <directory

SpringBoot启动报错Failed to determine a suitable driver class

此生再无相见时 提交于 2020-12-06 15:54:21
从 SpringBoot Initializer 新建SpringBoot项目添加一个简单控制器,启动报错如下: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2. 1.8 .RELEASE) 2019-09-09 10:37:16.750 INFO 11232 --- [ main] com.dongdong.demo.DemoApplication : Starting DemoApplication on PC-20170304VFOZ with PID 11232 (E:\Spring\Projects\demo\target\classes started by Administrator in E:\Spring\Projects\demo) 2019-09-09 10:37:16.752 INFO 11232 --- [ main] com

Failed to determine a suitable driver class(基于SpringBoot框架)

烂漫一生 提交于 2020-12-06 15:54:06
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.7.RELEASE) 2019-08-27 11:31:57.774 ERROR 15364 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver

springboot中json/xml与javabean互转

柔情痞子 提交于 2020-12-06 15:41:17
1:pom.xml中: <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> <version>2.9.9</version> </dependency> 2: @Component @Data @JacksonXmlRootElement(localName = "SomeModel") public class SomeModel { private String name; private int age; private String addr; @JacksonXmlElementWrapper(localName = "Myfriends") @JacksonXmlProperty(localName = "string") //注意:即使换成int程序也不会出异常 private List<String> friends; } 3: @Autowired

Springboot 抛出Failed to determine a suitable driver class异常原因

风流意气都作罢 提交于 2020-12-06 14:47:12
Springboot 抛出Failed to determine a suitable driver class异常原因 参考文章: (1)Springboot 抛出Failed to determine a suitable driver class异常原因 (2)https://www.cnblogs.com/XingXiaoMeng/p/11588666.html 备忘一下。 来源: oschina 链接: https://my.oschina.net/u/4428122/blog/4776929

Thymeleaf前后端传值 页面取值与js取值

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-06 12:40:54
参考:  Thymeleaf前后端传值 页面取值与js取值      Thymeleaf 与 Javascript Thymeleaf教程 (十二) 标签内,js中使用表达式 目的: 后端通过Model传值到前端 页面通过Model取值显示 js通过Model取值作为变量使用 1.后台Controller @GetMapping("/message") public String getMessage(Model model){ model.addAttribute("message","This is your message"); return "index"; } 注:向model中添加属性message 2.页面通过Model取值 <p th:text="#{message}">default message</p> 3.js通过model取值 <script th:inline="javascript"> var message = [[${message}]]; console.log(message); </script> 注:script标签中 th:inline 一定不能少,通常在取值的前后会加上不同的注释 4.如果前端需要接受的是一个JSON格式的对象,一定不能直接传JSON字符串 可以使用Fastjson将其转换为JSON对象package