一、使用Idea创建SpringInitializr项目,Pom.xml配置如下:
"1.0" encoding="UTF-8" ?>
"http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" >
4. 0. 0</ modelVersion>
org. springframework. boot</ groupId>
spring- boot- starter- parent</ artifactId>
2. 3. 1. RELEASE</ version>
/> <! -- lookup parent from repository -- >
</ parent>
com. byky</ groupId>
sendmessage</ artifactId>
0. 0. 1- SNAPSHOT</ version>
war</ packaging>
sendmessage</ name>
发送门店pos消费消息</ description>
.version>1. 8</ java. version>
</ properties>
org. springframework. boot</ groupId>
spring- boot- starter- data - redis</ artifactId>
spring- boot- starter- logging</ artifactId>
org. springframework. boot</ groupId>
</ exclusion>
</ exclusions>
</ dependency>
org. apache. commons</ groupId>
commons- pool2</ artifactId>
</ dependency>
<! -- 需要单独添加thymeleaf的布局模块 -- >
nz. net. ultraq. thymeleaf</ groupId>
thymeleaf- layout- dialect</ artifactId>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- starter- thymeleaf</ artifactId>
spring- boot- starter- logging</ artifactId>
org. springframework. boot</ groupId>
</ exclusion>
</ exclusions>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- starter- web</ artifactId>
org. springframework. boot</ groupId>
spring- boot- starter- tomcat</ artifactId>
</ exclusion>
</ exclusions>
</ dependency>
org. mybatis. spring. boot</ groupId>
mybatis- spring- boot- starter</ artifactId>
2. 1. 3</ version>
spring- boot- starter- logging</ artifactId>
org. springframework. boot</ groupId>
</ exclusion>
</ exclusions>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- devtools</ artifactId>
runtime</ scope>
true</ optional>
</ dependency>
com. oracle. ojdbc</ groupId>
ojdbc8</ artifactId>
runtime</ scope>
</ dependency>
mysql</ groupId>
mysql- connector- java</ artifactId>
runtime</ scope>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- starter- tomcat</ artifactId>
provided</ scope>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- starter- test</ artifactId>
test</ scope>
org. junit. vintage</ groupId>
junit- vintage- engine</ artifactId>
</ exclusion>
</ exclusions>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- starter- log4j2</ artifactId>
</ dependency>
org. mybatis. generator</ groupId>
mybatis- generator- core</ artifactId>
1. 4. 0</ version>
</ dependency>
<! -- 分页插件-- >
com. github. pagehelper</ groupId>
pagehelper</ artifactId>
5. 1. 11</ version>
</ dependency>
net. sf. json- lib</ groupId>
json- lib</ artifactId>
2. 4</ version>
jdk15</ classifier>
</ dependency>
javax. servlet</ groupId>
javax. servlet- api</ artifactId>
4. 0. 1</ version>
</ dependency>
<! -- 用于解决: uncategorized SQLException; SQL state [ 99999] ; error code [ 17056] ; 不支持的字符集 ( 在类路径中添加 orai18n. jar) : ZHS16GBK; nested exception is java. sql. SQLException: 不支持的字符集 ( 在类路径中添加 orai18n. jar) : ZHS16GBK] with root cause java. sql. SQLException: 不支持的字符集 ( 在类路径中添加 orai18n. jar) : ZHS16GBK -- >
cn. easyproject</ groupId>
orai18n</ artifactId>
12. 1. 0. 2. 0</ version>
</ dependency>
</ dependencies>
org. springframework. boot</ groupId>
spring- boot- maven- plugin</ artifactId>
</ plugin>
<! -- mybatis逆向工程maven插件-- >
org. mybatis. generator</ groupId>
mybatis- generator- maven- plugin</ artifactId>
1. 4. 0</ version>
<! -- 允许移动生成的文件-- >
true</ verbose>
<! -- 允许覆盖生成的文件-- >
true</ overwrite>
<! -- 配置文件的路径 默认resources目录下-- >
src/ main/ resources/ generatorConfig. xml</ configurationFile>
</ configuration>
<! -- 插件依赖的jar包-- >
com. oracle. ojdbc</ groupId>
ojdbc8</ artifactId>
19. 3. 0. 0</ version>
</ dependency>
cn. easyproject</ groupId>
orai18n</ artifactId>
12. 1. 0. 2. 0</ version>
</ dependency>
</ dependencies>
</ plugin>
</ plugins>
</ build>
</ project>
打包方式选择的是War方式,所以在web的依赖中排除tomcat依赖,代码如下:
org. springframework. boot</ groupId>
spring- boot- starter- web</ artifactId>
org. springframework. boot</ groupId>
spring- boot- starter- tomcat</ artifactId>
</ exclusion>
</ exclusions>
</ dependency>
tomcat的编译方式选择provided,只在编译和测试时使用,打包时不发布,因为启动时使用的war发布到Tomcat容器。
二、排除SpringBoot2.3.1默认使用的日志依赖。改为Log4j2日志系统 1、在pom.xml文件中引入log4j2的依赖,上步中已经引入了,此处摘选出代码片段
org. springframework. boot</ groupId>
spring- boot- starter- log4j2</ artifactId>
</ dependency>
2、在idea中打开依赖关系图,方式如下 图中小红框时如何打开图中右侧依赖关系图的按钮,图中左侧大红框所选的spring-boot-starter-logging它依赖于logback-classic,logback是springboot2.X的默认日志实现,所以这里点击红框所选的spring-boot-starter-logging,然后右击点击排除,图下图 此时就排除了默认使用的logback日志包了,具体排除后一些包中排除效果在pom.xml中是这样的
org. mybatis. spring. boot</ groupId>
mybatis- spring- boot- starter</ artifactId>
2. 1. 3</ version>
spring- boot- starter- logging</ artifactId>
org. springframework. boot</ groupId>
</ exclusion>
</ exclusions>
</ dependency>
org. springframework. boot</ groupId>
spring- boot- starter- thymeleaf</ artifactId>
spring- boot- starter- logging</ artifactId>
org. springframework. boot</ groupId>
</ exclusion>
</ exclusions>
</ dependency>
如果按照上面步骤排除后,运行时报错提示slf4j等日志重复就说明没有排除干净,按照上面步骤在依赖引用图中再次查找spring-boot-starter-logging,找到后右键排除。只要报日志重复错误就需要排除一次。 到此,日志系统已经改成log4j2,下面需要将log4j2的配置文件放置到资源文件夹中。 三、引入MyBatis分页插件及代码生成器 pom.xml中增加两个依赖,一个是分页插件,一个是代码生成器
org. mybatis. generator</ groupId>
mybatis- generator- core</ artifactId>
1. 4. 0</ version>
</ dependency>
<! -- 分页插件-- >
com. github. pagehelper</ groupId>
pagehelper</ artifactId>
5. 1. 11</ version>
</ dependency>
在Pom.xml中中添加代码生成器插件,代码如下
org. springframework. boot</ groupId>
spring- boot- maven- plugin</ artifactId>
</ plugin>
<! -- mybatis逆向工程maven插件-- >
org. mybatis. generator</ groupId>
mybatis- generator- maven- plugin</ artifactId>
1. 4. 0</ version>
<! -- 允许移动生成的文件-- >
true</ verbose>
<! -- 允许覆盖生成的文件-- >
true</ overwrite>
<! -- 配置文件的路径 默认resources目录下-- >
src/ main/ resources/ generatorConfig. xml</ configurationFile>
</ configuration>
<! -- 插件依赖的jar包-- >
com. oracle. ojdbc</ groupId>
ojdbc8</ artifactId>
19. 3. 0. 0</ version>
</ dependency>
cn. easyproject</ groupId>
orai18n</ artifactId>
12. 1. 0. 2. 0</ version>
</ dependency>
</ dependencies>
</ plugin>
</ plugins>
</ build>
注意下面这个插件是代码生成器,生成器插件中需要依赖数据库驱动包。 另外需要加入orai18n依赖解决" 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK"报错。 添加后,将代码生成器配置文件generatorConfig.xml放在资源文件夹中,配置文件代码如下:
"1.0" encoding="UTF-8" ?>
<! DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<! --
targetRuntime="MyBatis3" , 生成 Example相关类及方法
targetRuntime="MyBatis3Simple" , 不生成 Example相关类及方法
-- >
"MysqlTables" targetRuntime="MyBatis3" >
<! -- 指定生成 Mapper 的继承模板 -- >
<! -- type="tk.mybatis.mapper.generator.MapperPlugin" >
"mappers" value="" / >
</ plugin>-- >
<! -- 生成 JavaBean 对象重写 toString方法 -- >
type="org.mybatis.generator.plugins.ToStringPlugin" / >
<! -- 生成 JavaBean 对象继承 Serializable 类 -- >
type="org.mybatis.generator.plugins.SerializablePlugin" / >
<! -- 生成 JavaBean 对象重写 equals 和 hashCode 方法 -- >
<! -- type="org.mybatis.generator.plugins.EqualsHashCodePlugin" / >-- >
"suppressDate" value="true" / >
<! -- 是否去除自动生成的注释 true:是 : false:否 -- >
"suppressAllComments" value="true" / >
</ commentGenerator>
<! -- 数据库链接URL,用户名、密码 -- >
"com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.1.110:3306/lovemall?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE&serverTimezone=UTC"
userId="root"
password="abc7048461" >
</ jdbcConnection>
<! -- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java. math. BigDecimal -- >
"forceBigDecimals" value="true" / >
</ javaTypeResolver>
<! -- 生成模型的包名和位置-- >
"com.example.testboot.repository" targetProject="src/main/java" >
"enableSubPackages" value="true" / >
"trimStrings" value="true" / >
</ javaModelGenerator>
<! -- 生成映射文件的包名和位置-- >
"com.dao" targetProject="src/main/resources" >
"enableSubPackages" value="true" / >
</ sqlMapGenerator>
<! --
生成DAO的包名和位置
type ="ANNOTATEDMAPPER" , 生成Java Model 和基于注解的Mapper对象
type ="MIXEDMAPPER" , 生成基于注解的Java Model 和相应的Mapper对象
type ="XMLMAPPER" , 生成SQLMap XML文件和独立的Mapper接口
-- >
type="ANNOTATEDMAPPER" targetPackage="com.example.testboot.dao" targetProject="src/main/java" >
"enableSubPackages" value="true" / >
</ javaClientGenerator>
<! -- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-- >
"c_customer" domainObjectName="Customer" >
<! -- "id" sqlStatement="JDBC" identity="true" / >-- >
<! -- Mysql 配置 -- >
"sys_Id" sqlStatement="Mysql" identity="true" / >
<! -- Oracle 配置 -- >
<! -- "id" sqlStatement="select SEQ_{1}.nextval from dual" identity="false" type ="pre" / > -- >
</ table>
<! -- "person" domainObjectName="Person"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false" >
</ table>-- >
</ context>
</ generatorConfiguration>
注意里面的一些参数需要修改,比如数据库连接地址,账户密码,生成文件存放位置等。
然后配置要生成表的信息:
"c_customer" domainObjectName="Customer" >
<! -- "id" sqlStatement="JDBC" identity="true" / >-- >
<! -- Mysql 配置 -- >
"sys_Id" sqlStatement="Mysql" identity="true" / >
<! -- Oracle 配置 -- >
<! -- "id" sqlStatement="select SEQ_{1}.nextval from dual" identity="false" type ="pre" / > -- >
</ table>
配置后,在Maven的Plugins中选择代码生成器插件双击生成文件即可。 四、SpringBoot2.3 配置MyBatis 1、配置application.properties中两个数据源的属性
spring. thymeleaf. cache=false
spring. servlet. multipart. max- file- size=10MB
spring. servlet. multipart. max- request- size=10MB
app. datasource. first. driver- class - name=oracle. jdbc. driver. OracleDriver
app. datasource. first. jdbc- url=jdbc:oracle:thin:@192. 168. 2. 143:1521:testdb
app. datasource. first. username=sa
app. datasource. first. password=abc123456
app. datasource. first. type =com. zaxxer. hikari. HikariDataSource
app. datasource. first. hikari. minimum- idle=5
app. datasource. first. hikari. maximum- pool- size=500
app. datasource. first. hikari. auto- commit=true
app. datasource. first. hikari. idle- timeout=30000
app. datasource. first. hikari. pool- name=DatebookHikariCP1
app. datasource. first. hikari. max- lifetime=1800000
app. datasource. first. hikari. connection- timeout=30000
app. datasource. first. hikari. connection- test- query=SELECT 1
app. datasource. second. driver- class - name=com. mysql. cj. jdbc. Driver
app. datasource. second. jdbc- url=jdbc:mysql:/ / 192. 168. 1. 111:3306/ love?&serverTimezone=UTC&autoReconnect=true&useUnicode=true&characterEncoding=utf- 8&allowMultiQueries=true
app. datasource. second. username=root
app. datasource. second. password=abc777777
app. datasource. second. type =com. zaxxer. hikari. HikariDataSource
app. datasource. second. hikari. minimum- idle=5
app. datasource. second. hikari. maximum- pool- size=500
app. datasource. second. hikari. auto- commit=true
app. datasource. second. hikari. idle- timeout=30000
app. datasource. second. hikari. pool- name=DatebookHikariCP2
app. datasource. second. hikari. max- lifetime=1800000
app. datasource. second. hikari. connection- timeout=30000
app. datasource. second. hikari. connection- test- query=SELECT 1
2、在springboot入口类上进行配置
@SpringBootApplication ( exclude = { DataSourceAutoConfiguration. class } )
@MapperScan ( basePackages= "com.byky.sendmessage.mapper" , sqlSessionFactoryRef= "firstSqlSessionFactory" )
public class SendmessageApplication {
public static void main ( String[ ] args) {
SpringApplication. run ( SendmessageApplication. class , args) ;
}
@Bean
public TomcatServletWebServerFactory tomcatEmbedded ( ) {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory ( ) ;
tomcat. addConnectorCustomizers ( ( TomcatConnectorCustomizer) connector - > {
if ( ( connector. getProtocolHandler ( ) instanceof AbstractHttp11Protocol < ? > ) ) {
( ( AbstractHttp11Protocol< ? > ) connector. getProtocolHandler ( ) ) . setMaxSwallowSize ( - 1 ) ;
}
} ) ;
return tomcat;
}
}
首先:在@SpringBootApplication排除数据源自动配置类,方便手动配置数据源进行多数据源设置 第二步:在配置类上增加Mybatis的@MapperScan注解,注解中指明mapper类的位置及要引用的SqlSessionFactory Bean的名称(这个bean是需要手动定义的) @MapperScan(basePackages=“com.byky.sendmessage.mapper”,sqlSessionFactoryRef=“firstSqlSessionFactory”)
第三步:定义Mybatis需要的数据源、SqlSessionFactory、事务管理器等bean。代码如下:
@Configuration
public class MyBatisDataSourceConfig {
@Bean ( name= "firstDataSource" )
@ConfigurationProperties ( prefix= "app.datasource.first" )
@Primary
public DataSource firstDataSource ( ) {
return DataSourceBuilder. create ( ) . build ( ) ;
}
@Bean ( name = "firstSqlSessionFactory" )
@Primary
public SqlSessionFactory firstSqlSessionFactory ( @Qualifier ( "firstDataSource" ) DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean ( ) ;
bean. setDataSource ( dataSource) ;
Interceptor interceptor = new PageInterceptor ( ) ;
Properties properties = new Properties ( ) ;
properties. setProperty ( "helperDialect" , "oracle" ) ;
properties. setProperty ( "offsetAsPageNum" , "true" ) ;
properties. setProperty ( "rowBoundsWithCount" , "true" ) ;
properties. setProperty ( "reasonable" , "true" ) ;
properties. setProperty ( "supportMethodsArguments" , "true" ) ;
interceptor. setProperties ( properties) ;
bean. setPlugins ( new Interceptor [ ] { interceptor} ) ;
return bean. getObject ( ) ;
}
@Bean ( name = "firstTransactionManager" )
@Primary
public DataSourceTransactionManager firstTransactionManager ( @Qualifier ( "firstDataSource" ) DataSource dataSource) {
return new DataSourceTransactionManager ( dataSource) ;
}
@Bean ( name= "firstSqlSessionTemplate" )
@Primary
public SqlSessionTemplate firstSqlSessionTemplate ( @Qualifier ( "firstSqlSessionFactory" ) SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate ( sqlSessionFactory) ;
}
@Bean ( name= "secondDataSource" )
@ConfigurationProperties ( prefix= "app.datasource.second" )
public DataSource secondDataSource ( ) {
return DataSourceBuilder. create ( ) . build ( ) ;
}
@Bean ( name = "secondSqlSessionFactory" )
public SqlSessionFactory secondSqlSessionFactory ( @Qualifier ( "secondDataSource" ) DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean ( ) ;
bean. setDataSource ( dataSource) ;
Interceptor interceptor = new PageInterceptor ( ) ;
Properties properties = new Properties ( ) ;
properties. setProperty ( "helperDialect" , "mysql" ) ;
properties. setProperty ( "offsetAsPageNum" , "true" ) ;
properties. setProperty ( "rowBoundsWithCount" , "true" ) ;
properties. setProperty ( "reasonable" , "true" ) ;
properties. setProperty ( "supportMethodsArguments" , "true" ) ;
interceptor. setProperties ( properties) ;
bean. setPlugins ( new Interceptor [ ] { interceptor} ) ;
return bean. getObject ( ) ;
}
@Bean ( name = "secondTransactionManager" )
public DataSourceTransactionManager secondTransactionManager ( @Qualifier ( "secondDataSource" ) DataSource dataSource) {
return new DataSourceTransactionManager ( dataSource) ;
}
@Bean ( name= "secondSqlSessionTemplate" )
public SqlSessionTemplate secondSqlSessionTemplate ( @Qualifier ( "secondSqlSessionFactory" ) SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate ( sqlSessionFactory) ;
}
此时一个完整的springboot+mybatis已经配置好了。上面代码中在定义SqlSessionFactory 时,里面增加了一个分页拦截器配置文件,在pom.xml中引入分页依赖后在定义SqlSessionFactory时加入分页拦截器的配置参数后,分页文件就可以直接在mapper中进行定义。
关于分页这里有几点需要记录: 1、分页插件详情请看https://pagehelper.github.io/ 2、分页插件需要引入依赖和在SqlSessionFactory定义时配置了拦截器参数 3、使用分页时,可以直接在mapper的具体方法中,增加@Param(“pageNum”) int pageNum,@Param(“pageSize”) int pageSize类型参数,系统会自动分页。 如果是复杂查询,传入的参数是实例类型的,只需要在实例的类中定义 int pageNum, int pageSize属性即可直接实现分页。
你可能感兴趣的:(SpringBoot2.X,mybatis,spring)
SpringBlade dict-biz/list 接口 SQL 注入漏洞
文章永久免费只为良心
oracle 数据库
SpringBladedict-biz/list接口SQL注入漏洞POC:构造请求包查看返回包你的网址/api/blade-system/dict-biz/list?updatexml(1,concat(0x7e,md5(1),0x7e),1)=1漏洞概述在SpringBlade框架中,如果dict-biz/list接口的后台处理逻辑没有正确地对用户输入进行过滤或参数化查询(PreparedSta
insert into select 主键自增_mybatis拦截器实现主键自动生成
weixin_39521651
insert into select 主键自增 mybatis delete返回值 mybatis insert返回主键 mybatis insert返回对象 mybatis plus insert返回主键 mybatis plus 插入生成id
前言前阵子和朋友聊天,他说他们项目有个需求,要实现主键自动生成,不想每次新增的时候,都手动设置主键。于是我就问他,那你们数据库表设置主键自动递增不就得了。他的回答是他们项目目前的id都是采用雪花算法来生成,因此为了项目稳定性,不会切换id的生成方式。朋友问我有没有什么实现思路,他们公司的orm框架是mybatis,我就建议他说,不然让你老大把mybatis切换成mybatis-plus。mybat
spring如何整合druid连接池?
惜.己
spring spring junit 数据库 java idea 后端 xml
目录spring整合druid连接池1.新建maven项目2.新建mavenModule3.导入相关依赖4.配置log4j2.xml5.配置druid.xml1)xml中如何引入properties2)下面是配置文件6.准备jdbc.propertiesJDBC配置项解释7.配置druid8.测试spring整合druid连接池1.新建maven项目打开IDE(比如IntelliJIDEA,Ecl
SpringCloudAlibaba—Sentinel(限流)
菜鸟爪哇
前言:自己在学习过程的记录,借鉴别人文章,记录自己实现的步骤。借鉴文章:https://blog.csdn.net/u014494148/article/details/105484410Sentinel介绍Sentinel诞生于阿里巴巴,其主要目标是流量控制和服务熔断。Sentinel是通过限制并发线程的数量(即信号隔离)来减少不稳定资源的影响,而不是使用线程池,省去了线程切换的性能开销。当资源
springboot+vue项目实战一-创建SpringBoot简单项目
苹果酱0567
面试题汇总与解析 spring boot 后端 java 中间件 开发语言
这段时间抽空给女朋友搭建一个个人博客,想着记录一下建站的过程,就当做笔记吧。虽然复制zjblog只要一个小时就可以搞定一个网站,或者用cms系统,三四个小时就可以做出一个前后台都有的网站,而且想做成啥样也都行。但是就是要从新做,自己做的意义不一样,更何况,俺就是专门干这个的,嘿嘿嘿要做一个网站,而且从零开始,首先呢就是技术选型了,经过一番思量决定选择-SpringBoot做后端,前端使用Vue做一
Spring MVC 全面指南:从入门到精通的详细解析
一杯梅子酱
技术栈学习 spring mvc java
引言:SpringMVC,作为Spring框架的一个重要模块,为构建Web应用提供了强大的功能和灵活性。无论是初学者还是有一定经验的开发者,掌握SpringMVC都将显著提升你的Web开发技能。本文旨在为初学者提供一个全面且易于理解的学习路径,通过详细的知识点分析和实际案例,帮助你快速上手SpringMVC,让学习过程既深刻又高效。一、SpringMVC简介1.1什么是SpringMVC?Spri
Spring Boot中实现跨域请求
BABA8891
spring boot 后端 java
在SpringBoot中实现跨域请求(CORS,Cross-OriginResourceSharing)可以通过多种方式,以下是几种常见的方法:1.使用@CrossOrigin注解在SpringBoot中,你可以在控制器或者具体的请求处理方法上使用@CrossOrigin注解来允许跨域请求。在控制器上应用:importorg.springframework.web.bind.annotation.
博客网站制作教程
2401_85194651
java maven
首先就是技术框架:后端:Java+SpringBoot数据库:MySQL前端:Vue.js数据库连接:JPA(JavaPersistenceAPI)1.项目结构blog-app/├──backend/│├──src/main/java/com/example/blogapp/││├──BlogApplication.java││├──config/│││└──DatabaseConfig.java
RabbitMQ生产者重复机制与确认机制
java炒饭小能手
java-rabbitmq rabbitmq java
重复机制生产者发送消息时,出现了网络故障,导致与MQ的连接中断。为了解决这个问题,SpringAMQP提供的消息发送时的重试机制。即:当RabbitTemplate与MQ连接超时后,多次重试。需要修该发送端模块的application.yaml文件,添加下面的内容:spring:rabbitmq:connection-timeout:1s#设置MQ的连接超时时间template:retry:ena
MyBatis 详解
阿贾克斯的黎明
java mybatis
目录目录一、MyBatis是什么二、为什么使用MyBatis(一)灵活性高(二)性能优化(三)易于维护三、怎么用MyBatis(一)添加依赖(二)配置MyBatis(三)创建实体类和接口(四)使用MyBatis一、MyBatis是什么MyBatis是一个优秀的持久层框架,它支持自定义SQL、存储过程以及高级映射。MyBatis免除了几乎所有的JDBC代码以及设置参数和获取结果集的工作。它可以通过简
【Java】已解决:org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException
屿小夏
java 开发语言
文章目录一、分析问题背景问题背景描述出现问题的场景二、可能出错的原因三、错误代码示例四、正确代码示例五、注意事项已解决:org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException在使用Spring框架进行开发时,数据源的配置和使用是非常关键的一环。然而,有时候我们可能会遇到org.springframewo
SpringBoot和SpringMVC是什么关系?SpringBoot替代SpringMVC了吗?
瑞金彭于晏
spring boot 后端 java MVC spring 数据库
SpringBoot和SpringMVC都是SpringFramework生态系统中的一部分,但它们各自扮演着不同的角色和提供不同的功能集。理解它们之间的关系,首先需要了解SpringFramework本身。SpringFrameworkSpringFramework是一个全面的、开源的应用程序开发框架,它提供了广泛的功能来支持企业应用开发的几乎所有方面。SpringFramework的核心特性之
spring mvc @RequestBody String类型参数
zoyation
spring-mvc spring mvc
通过如下配置:text/html;charset=UTF-8application/json;charset=UTF-8在springmvc的Controller层使用@RequestBody接收Content-Type为application/json的数据时,默认支持Map方式和对象方式参数@RequestMapping(value="/{code}/saveUser",method=Requ
Java -jar 如何在后台运行项目
vincent_hahaha
撸了今年阿里、头条和美团的面试,我有一个重要发现.......>>>说到运行jar包通常我们都会以下面的方式运行:java-jarspringboot-0.0.1-SNAPSHOT.jar这样运行的话会有一个问题,就是我们一关闭当前窗口就会停止运行项目,要想解决这个问题,就需要在后台运行。nohupjava-jarbabyshark-0.0.1-SNAPSHOT.jar >log.file 2>&
spring security中几大组件的作用和执行顺序
阿信在这里
java spring
springsecurity中几大组件的作用和执行顺序在SpringSecurity中,AuthenticationProvider、GroupPermissionEvaluator、PermissionEvaluator、AbstractAuthenticationProcessingFilter、DefaultMethodSecurityExpressionHandler和ManageSecu
探索Zebra4J:构建高效企业级Web应用的微服务框架
叶准鑫Natalie
探索Zebra4J:构建高效企业级Web应用的微服务框架ZebraZebra4J/Zebra4Js基于SpringBoot的JavaWeb/Nodejs框架项目地址:https://gitcode.com/gh_mirrors/zebra/Zebra项目介绍在当今快速发展的技术环境中,构建高效、可扩展的企业级Web应用是每个开发团队的追求。Zebra4J作为一款基于SpringBoot的全新微服务
mybatis 二级缓存失效_Mybatis 缓存原理及失效情况解析
weixin_39844942
mybatis 二级缓存失效
这篇文章主要介绍了Mybatis缓存原理及失效情况解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下1、什么是缓存[Cache]存在内存中的临时数据。将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效率,解决了高并发系统的性能问题。2、为什么要使用缓存减少和数据库的交互次
基于JavaWeb开发的Java+SpringMvc+vue+element实现上海汽车博物馆平台
网顺技术团队
成品程序项目 java vue.js 汽车 课程设计 spring boot
基于JavaWeb开发的Java+SpringMvc+vue+element实现上海汽车博物馆平台作者主页网顺技术团队欢迎点赞收藏⭐留言文末获取源码联系方式查看下方微信号获取联系方式承接各种定制系统精彩系列推荐精彩专栏推荐订阅不然下次找不到哟Java毕设项目精品实战案例《1000套》感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人文章目录基
分布式锁和spring事务管理
暴躁的鱼
锁及事务 分布式 spring java
最近开发一个小程序遇到一个需求需要实现分布式事务管理业务需求用户在使用小程序的过程中可以查看景点,对景点地区或者城市标记是否想去,那么需要统计一个地点被标记的人数,以及记录某个用户对某个地点是否标记为想去,用两个表存储数据,一个地点表记录改地点被标记的次数,一个用户意向表记录某个用户对某个地点是否标记为想去。由于可能有多个用户同时标记一个地点,每个用户在前端点击想去按钮之后,后台接收到请求,从数据
详解mybatis的一二级缓存以及缓存失效原因
仰望天花板
缓存 数据库 mybatis java mysql
数据库的大部分场景下是从磁盘读取,如果数据从内存进行读取,速度较比磁盘要快得多。但因为内存的容量有限,所以一般只会把使用和查询较多的数据缓存起来,以便快速反应,其他使用率不太多的继续存放在磁盘。mybatis分为一级缓存和二级缓存1.一级缓存一级缓存存放在SqlSqeeion上,默认开启1.1pojo@DatapublicclassRole{privateLongid;privateStringr
Java面试笔记记录6
今天背八股了吗
java 面试 笔记
1.Spring是什么?特性?有哪些模块?Spring是一个轻量级、非入侵式的控制反转Ioc和面向切面AOP的框架。特性:1.Ioc和DISpring的核心就是一个大的工厂容器,可以维护所有对象的创建和依赖关系,Spring工厂用于生成Bean,并且管理Bean的生命周期,实现高内聚低耦合的设计理念。2.AOP编程Spring提供面向切面编程,可以方便实现对程序进行权限拦截、运行监控等切面功能。3
Sentinel
眼泪落在琴弦
springcloud java java
Sentinel(服务熔断降级限流)1.引入spring-cloud-starter-alibaba-sentinel2.下载sentinel服务器3.配置application地址信息4.在控制台调整参数【默认所以流控设置保存在内存中,重启失效】5.想实时监控需每个微服务导入actuator,并配置application暴露所有端口6.自定义sentinel流控返回数据7.配置sentinel类
Spring @Async 深度解读:默认线程池执行器的配置与优化
小码快撩
spring java 前端
在Spring中,@Async注解用于异步执行方法。默认情况下,@Async注解的任务是由一个线程池执行的。然而,这个默认的线程池是如何初始化的呢?本文将深入探讨这一过程,帮助你理解Spring异步任务背后的线程池执行器的初始化原理。1.@Async的基本使用首先,让我们快速回顾一下@Async的基本用法。@Async通常用于标注在需要异步执行的方法上,比如:@Servicepublicclass
Sentinel实时监控不展示问题
朱杰jjj
sentinel sentinel
问题官方插件Endpoint支持,可以实时统计出SpringBoot的健康状况和请求的调用信息在使用Endpoint特性之前需要在Maven中添加spring-boot-starter-actuator依赖,并在配置中允许Endpoints的访问。SpringBoot1.x中添加配置management.security.enabled=false。暴露的endpoint路径为/sentinelS
36. MyBatis如何支持多数据库操作?如何配置不同的数据源?
这孩子叫逆
Mybatis笔记 mybatis 数据库
在许多企业级应用中,可能需要访问多个数据库。MyBatis可以通过配置多个数据源和动态切换数据源来支持多数据库操作。下面介绍如何在MyBatis中配置和使用多个数据源。1.多数据源的基本配置1.1配置多个数据源要支持多个数据源,首先需要在Spring或SpringBoot中配置不同的数据源。假设我们要连接两个数据库db1和db2,可以通过以下步骤进行配置。SpringBoot示例:applicat
SpringBoot整合ES搜索引擎 实现网站热搜词及热度计算
码踏云端
springboot Elasticsearch spring boot elasticsearch 后端 热搜词 热度计算 java
博主简介:历代文学网(PC端可以访问:https://literature.sinhy.com/#/literature?__c=1000,移动端可微信小程序搜索“历代文学”)总架构师,15年工作经验,精通Java编程,高并发设计,Springboot和微服务,熟悉Linux,ESXI虚拟化以及云原生Docker和K8s,热衷于探索科技的边界,并将理论知识转化为实际应用。保持对新技术的好奇心,乐于
Spring Security静态资源过滤(11)
小黑屋说YYDS
spring
在一个实际项目中,并非所有的请求都需要经过SpringSecurity过滤器,有一些特殊的请求,例如静态资源等,一般来说并不需要经过SpringSecurity过滤器链,用户如果访问这些静态资源,直接返回对应的资源即可。回顾关于WebSecurity的讲解,提到它里边维护了一个ignoredRequests变量,该变量,记录的就是所有需要被忽略的请求,这些被忽略的请求将不再经过SpringSecu
MyBatis批量插入大量数据
小黑屋说YYDS
MyBatis java
1.思路分析批量插入这个问题,我们用JDBC操作,其实就是两种思路吧:用一个for循环,把数据一条一条的插入(这种需要开启批处理)。生成一条插入sql,类似这种insertintouser(username,address)values(‘aa’,‘bb’),(‘cc’,‘dd’)…。到底哪种快呢?我们从两方面来考虑这个问题:插入SQL本身执行的效率。网络I/O。先说第一种方案,就是用for循环循
Spring Security定义多个过滤器链(10)
小黑屋说YYDS
spring
在SpringSecurity中可以同时存在多个过滤器链,一个WebSecurityConfigurerAdapter的实例就可以配置一条过滤器链。我们来看如下一个案例:@ConfigurationpublicclassSecurityConfig{@BeanUserDetailsServiceus(){InMemoryUserDetailsManagerusers=newInMemoryUser
java 技术 架构 相关文档
圣心
java 架构 开发语言
在Java中,有许多不同的技术和架构,这里我将列举一些常见的Java技术和架构,并提供一些相关的文档资源。SpringFrameworkSpring是一个开源的Java/JavaEE全功能框架,以Apache许可证形式发布,提供了一种实现企业级应用的方法。官方文档:SpringFrameworkSpringBootSpringBoot是Spring的一个子项目,旨在简化创建生产级的Spring应用
LeetCode[Math] - #66 Plus One
Cwind
java LeetCode 题解 Algorithm Math
原题链接:#66 Plus One
要求:
给定一个用数字数组表示的非负整数,如num1 = {1, 2, 3, 9}, num2 = {9, 9}等,给这个数加上1。
注意:
1. 数字的较高位存在数组的头上,即num1表示数字1239
2. 每一位(数组中的每个元素)的取值范围为0~9
难度:简单
分析:
题目比较简单,只须从数组
JQuery中$.ajax()方法参数详解
AILIKES
JavaScript jsonp jquery Ajax json
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址。
type: 要求为String类型的参数,请求方式(post或get)默认为get。注意其他http请求方法,例如put和 delete也可以使用,但仅部分浏览器支持。
timeout: 要求为Number类型的参数,设置请求超时时间(毫秒)。此设置将覆盖$.ajaxSetup()方法的全局
JConsole & JVisualVM远程监视Webphere服务器JVM
Kai_Ge
JVisualVM JConsole Webphere
JConsole是JDK里自带的一个工具,可以监测Java程序运行时所有对象的申请、释放等动作,将内存管理的所有信息进行统计、分析、可视化。我们可以根据这些信息判断程序是否有内存泄漏问题。
使用JConsole工具来分析WAS的JVM问题,需要进行相关的配置。
首先我们看WAS服务器端的配置.
1、登录was控制台https://10.4.119.18
自定义annotation
120153216
annotation
Java annotation 自定义注释@interface的用法 一、什么是注释
说起注释,得先提一提什么是元数据(metadata)。所谓元数据就是数据的数据。也就是说,元数据是描述数据的。就象数据表中的字段一样,每个字段描述了这个字段下的数据的含义。而J2SE5.0中提供的注释就是java源代码的元数据,也就是说注释是描述java源
CentOS 5/6.X 使用 EPEL YUM源
2002wmj
centos
CentOS 6.X 安装使用EPEL YUM源1. 查看操作系统版本[root@node1 ~]# uname -a Linux node1.test.com 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@node1 ~]#
在SQLSERVER中查找缺失和无用的索引SQL
357029540
SQL Server
--缺失的索引
SELECT avg_total_user_cost * avg_user_impact * ( user_scans + user_seeks ) AS PossibleImprovement ,
last_user_seek ,
 
Spring3 MVC 笔记(二) —json+rest优化
7454103
Spring3 MVC
接上次的 spring mvc 注解的一些详细信息!
其实也是一些个人的学习笔记 呵呵!
替换“\”的时候报错Unexpected internal error near index 1 \ ^
adminjun
java “\替换”
发现还是有些东西没有刻子脑子里,,过段时间就没什么概念了,所以贴出来...以免再忘...
在拆分字符串时遇到通过 \ 来拆分,可是用所以想通过转义 \\ 来拆分的时候会报异常
public class Main {
/*
POJ 1035 Spell checker(哈希表)
aijuans
暴力求解--哈希表
/*
题意:输入字典,然后输入单词,判断字典中是否出现过该单词,或者是否进行删除、添加、替换操作,如果是,则输出对应的字典中的单词
要求按照输入时候的排名输出
题解:建立两个哈希表。一个存储字典和输入字典中单词的排名,一个进行最后输出的判重
*/
#include <iostream>
//#define
using namespace std;
const int HASH =
通过原型实现javascript Array的去重、最大值和最小值
ayaoxinchao
JavaScript array prototype
用原型函数(prototype)可以定义一些很方便的自定义函数,实现各种自定义功能。本次主要是实现了Array的去重、获取最大值和最小值。
实现代码如下:
<script type="text/javascript">
Array.prototype.unique = function() {
var a = {};
var le
UIWebView实现https双向认证请求
bewithme
UIWebView https Objective-C
什么是HTTPS双向认证我已在先前的博文 ASIHTTPRequest实现https双向认证请求
中有讲述,不理解的读者可以先复习一下。本文是用UIWebView来实现对需要客户端证书验证的服务请求,网上有些文章中有涉及到此内容,但都只言片语,没有讲完全,更没有完整的代码,让人困扰不已。但是此知
NoSQL数据库之Redis数据库管理(Redis高级应用之事务处理、持久化操作、pub_sub、虚拟内存)
bijian1013
redis 数据库 NoSQL
3.事务处理
Redis对事务的支持目前不比较简单。Redis只能保证一个client发起的事务中的命令可以连续的执行,而中间不会插入其他client的命令。当一个client在一个连接中发出multi命令时,这个连接会进入一个事务上下文,该连接后续的命令不会立即执行,而是先放到一个队列中,当执行exec命令时,redis会顺序的执行队列中
各数据库分页sql备忘
bingyingao
oracle sql 分页
ORACLE
下面这个效率很低
SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM IPAY_RCD_FS_RETURN order by id desc) A ) WHERE RN <20;
下面这个效率很高
SELECT A.*, ROWNUM RN FROM (SELECT * FROM IPAY_RCD_
【Scala七】Scala核心一:函数
bit1129
scala
1. 如果函数体只有一行代码,则可以不用写{},比如
def print(x: Int) = println(x)
一行上的多条语句用分号隔开,则只有第一句属于方法体,例如
def printWithValue(x: Int) : String= println(x); "ABC"
上面的代码报错,因为,printWithValue的方法
了解GHC的factorial编译过程
bookjovi
haskell
GHC相对其他主流语言的编译器或解释器还是比较复杂的,一部分原因是haskell本身的设计就不易于实现compiler,如lazy特性,static typed,类型推导等。
关于GHC的内部实现有篇文章说的挺好,这里,文中在RTS一节中详细说了haskell的concurrent实现,里面提到了green thread,如果熟悉Go语言的话就会发现,ghc的concurrent实现和Go有点类
Java-Collections Framework学习与总结-LinkedHashMap
BrokenDreams
LinkedHashMap
前面总结了java.util.HashMap,了解了其内部由散列表实现,每个桶内是一个单向链表。那有没有双向链表的实现呢?双向链表的实现会具备什么特性呢?来看一下HashMap的一个子类——java.util.LinkedHashMap。
读《研磨设计模式》-代码笔记-抽象工厂模式-Abstract Factory
bylijinnan
abstract
声明: 本文只为方便我个人查阅和理解,详细的分析以及源代码请移步 原作者的博客http://chjavach.iteye.com/
package design.pattern;
/*
* Abstract Factory Pattern
* 抽象工厂模式的目的是:
* 通过在抽象工厂里面定义一组产品接口,方便地切换“产品簇”
* 这些接口是相关或者相依赖的
压暗面部高光
cherishLC
PS
方法一、压暗高光&重新着色
当皮肤很油又使用闪光灯时,很容易在面部形成高光区域。
下面讲一下我今天处理高光区域的心得:
皮肤可以分为纹理和色彩两个属性。其中纹理主要由亮度通道(Lab模式的L通道)决定,色彩则由a、b通道确定。
处理思路为在保持高光区域纹理的情况下,对高光区域着色。具体步骤为:降低高光区域的整体的亮度,再进行着色。
如果想简化步骤,可以只进行着色(参看下面的步骤1
Java VisualVM监控远程JVM
crabdave
visualvm
Java VisualVM监控远程JVM
JDK1.6开始自带的VisualVM就是不错的监控工具.
这个工具就在JAVA_HOME\bin\目录下的jvisualvm.exe, 双击这个文件就能看到界面
通过JMX连接远程机器, 需要经过下面的配置:
1. 修改远程机器JDK配置文件 (我这里远程机器是linux).
 
Saiku去掉登录模块
daizj
saiku 登录 olap BI
1、修改applicationContext-saiku-webapp.xml
<security:intercept-url pattern="/rest/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:intercept-url pattern=&qu
浅析 Flex中的Focus
dsjt
html Flex Flash
关键字:focus、 setFocus、 IFocusManager、KeyboardEvent
焦点、设置焦点、获得焦点、键盘事件
一、无焦点的困扰——组件监听不到键盘事件
原因:只有获得焦点的组件(确切说是InteractiveObject)才能监听到键盘事件的目标阶段;键盘事件(flash.events.KeyboardEvent)参与冒泡阶段,所以焦点组件的父项(以及它爸
Yii全局函数使用
dcj3sjt126com
yii
由于YII致力于完美的整合第三方库,它并没有定义任何全局函数。yii中的每一个应用都需要全类别和对象范围。例如,Yii::app()->user;Yii::app()->params['name'];等等。我们可以自行设定全局函数,使得代码看起来更加简洁易用。(原文地址)
我们可以保存在globals.php在protected目录下。然后,在入口脚本index.php的,我们包括在
设计模式之单例模式二(解决无序写入的问题)
come_for_dream
单例模式 volatile 乱序执行 双重检验锁
在上篇文章中我们使用了双重检验锁的方式避免懒汉式单例模式下由于多线程造成的实例被多次创建的问题,但是因为由于JVM为了使得处理器内部的运算单元能充分利用,处理器可能会对输入代码进行乱序执行(Out Of Order Execute)优化,处理器会在计算之后将乱序执行的结果进行重组,保证该
程序员从初级到高级的蜕变
gcq511120594
框架 工作 PHP android html5
软件开发是一个奇怪的行业,市场远远供不应求。这是一个已经存在多年的问题,而且随着时间的流逝,愈演愈烈。
我们严重缺乏能够满足需求的人才。这个行业相当年轻。大多数软件项目是失败的。几乎所有的项目都会超出预算。我们解决问题的最佳指导方针可以归结为——“用一些通用方法去解决问题,当然这些方法常常不管用,于是,唯一能做的就是不断地尝试,逐个看看是否奏效”。
现在我们把淫浸代码时间超过3年的开发人员称为
Reverse Linked List
hcx2013
list
Reverse a singly linked list.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
p
Spring4.1新特性——数据库集成测试
jinnianshilongnian
spring 4.1
目录
Spring4.1新特性——综述
Spring4.1新特性——Spring核心部分及其他
Spring4.1新特性——Spring缓存框架增强
Spring4.1新特性——异步调用和事件机制的异常处理
Spring4.1新特性——数据库集成测试脚本初始化
Spring4.1新特性——Spring MVC增强
Spring4.1新特性——页面自动化测试框架Spring MVC T
C# Ajax上传图片同时生成微缩图(附Demo)
liyonghui160com
1.Ajax无刷新上传图片,详情请阅我的这篇文章。(jquery + c# ashx)
2.C#位图处理 System.Drawing。
3.最新demo支持IE7,IE8,Fir
Java list三种遍历方法性能比较
pda158
java
从c/c++语言转向java开发,学习java语言list遍历的三种方法,顺便测试各种遍历方法的性能,测试方法为在ArrayList中插入1千万条记录,然后遍历ArrayList,发现了一个奇怪的现象,测试代码例如以下:
package com.hisense.tiger.list;
import java.util.ArrayList;
import java.util.Iterator;
300个涵盖IT各方面的免费资源(上)——商业与市场篇
shoothao
seo 商业与市场 IT资源 免费资源
A.网站模板+logo+服务器主机+发票生成
HTML5 UP:响应式的HTML5和CSS3网站模板。
Bootswatch:免费的Bootstrap主题。
Templated:收集了845个免费的CSS和HTML5网站模板。
Wordpress.org|Wordpress.com:可免费创建你的新网站。
Strikingly:关注领域中免费无限的移动优
localStorage、sessionStorage
uule
localStorage
W3School 例子
HTML5 提供了两种在客户端存储数据的新方法:
localStorage - 没有时间限制的数据存储
sessionStorage - 针对一个 session 的数据存储
之前,这些都是由 cookie 完成的。但是 cookie 不适合大量数据的存储,因为它们由每个对服务器的请求来传递,这使得 cookie 速度很慢而且效率也不