热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

11、SpringBootmybatisplusdruid多源数据事务

系列导航1、springboot工程新建(单模块)2、springboot创建多模块工程3、springboot连接数据库4、SpringBoot连接数据库引入druid5、Spr

系列导航

1、springboot工程新建(单模块)

2、springboot创建多模块工程

3、springboot连接数据库

4、SpringBoot连接数据库引入druid

5、SpringBoot连接数据库引入mybatis

6、SpringBoot-mybatis分页实现pagehelper

7、SpringBoot-mybatis-plus引入

8、SpringBoot 事务

9、SpringBoot-mybatis-druid多源数据多源数据

10、SpringBoot-mybatis-plus-druid多源数据

11、SpringBoot-mybatis-plus-druid多源数据事务

未完待续

      上一篇博客中因为多源项目的事务没有解决,本篇博客介绍一种可以在多源项目中让事务生效的方法,mybatis-plus配置多源数据还要使的事务生效,需要引入新的依赖atomikos


1数据库中创建表

zy数据库:

CREATE TABLE TEST_BLOCK_T
(
BLOCK_ID VARCHAR2(10 BYTE) PRIMARY KEY, --编码
BLOCK_NAME VARCHAR2(200 BYTE) --资源名称
);
Insert into TEST_BLOCK_T (BLOCK_ID, BLOCK_NAME) Values ('1', 'java');
COMMIT;

yc数据库:

CREATE TABLE TEST_USER_T
(
USER_ID VARCHAR2(10 BYTE) PRIMARY KEY,
NAME VARCHAR2(200 BYTE)
);
Insert into TEST_USER_T (USER_ID, NAME) Values ('1', '张三');
COMMIT;

 


2、pom.xml


1.8

UTF-8

UTF-8
2.1.17.RELEASE



org.springframework.boot
spring-boot-starter-web


org.springframework.boot
spring-boot-starter-test
test



com.alibaba
druid-spring-boot-starter
1.1.20



com.baomidou
mybatis-plus-boot-starter
3.3.1



org.springframework.boot
spring-boot-starter-jta-atomikos



com.oracle
ojdbc6
11.2.0.3



org.projectlombok
lombok
true


3、      application.properties配置

# 应用名称
spring.application.name=demo
# 应用服务 WEB 访问端口
server.port=8080
spring.datasource.type=com.alibaba.druid.pool.xa.DruidXADataSource
spring.datasource.druid.one.name=oneDataSource
spring.datasource.druid.one.url=jdbc:oracle:thin:@192.168.0.100:1521:orcl
spring.datasource.druid.one.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.druid.one.username=zy
spring.datasource.druid.one.password=1
spring.datasource.druid.one.initialSize=5
spring.datasource.druid.one.minIdle=5
spring.datasource.druid.one.maxActive=20
spring.datasource.druid.one.maxWait=60000
spring.datasource.druid.one.timeBetweenEvictiOnRunsMillis=60000
spring.datasource.druid.one.minEvictableIdleTimeMillis=300000
spring.datasource.druid.one.validatiOnQuery= SELECT 1 from dual
spring.datasource.druid.one.validatiOnQueryTimeout=10000
spring.datasource.druid.one.testWhileIdle=true
spring.datasource.druid.one.testOnBorrow=false
spring.datasource.druid.one.testOnReturn=false
spring.datasource.druid.one.poolPreparedStatements=true
spring.datasource.druid.one.maxPoolPreparedStatementPerCOnnectionSize=20
spring.datasource.druid.one.filters=stat,wall
spring.datasource.druid.one.cOnnectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
spring.datasource.druid.one.useGlobalDataSourceStat=true
spring.datasource.druid.two.name=twoDataSource
spring.datasource.druid.two.url=jdbc:oracle:thin:@192.168.0.100:1521:orcl
spring.datasource.druid.two.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.druid.two.username=yc
spring.datasource.druid.two.password=1
spring.datasource.druid.two.initialSize=5
spring.datasource.druid.two.minIdle=5
spring.datasource.druid.two.maxActive=20
spring.datasource.druid.two.maxWait=60000
spring.datasource.druid.two.timeBetweenEvictiOnRunsMillis=60000
spring.datasource.druid.two.minEvictableIdleTimeMillis=300000
spring.datasource.druid.two.validatiOnQuery=SELECT 1 from dual
spring.datasource.druid.two.validatiOnQueryTimeout=10000
spring.datasource.druid.two.testWhileIdle=true
spring.datasource.druid.two.testOnBorrow=false
spring.datasource.druid.two.testOnReturn=false
spring.datasource.druid.two.poolPreparedStatements=true
spring.datasource.druid.two.maxPoolPreparedStatementPerCOnnectionSize=20
spring.datasource.druid.two.filters=stat,wall
spring.datasource.druid.two.cOnnectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
spring.datasource.druid.two.useGlobalDataSourceStat=true
spring.jta.atomikos.properties.log-base-dir=tx-logs
spring.jta.transaction-manager-id=txManager

 


4、文件目录

 

 

5、源码

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
private org.springframework.dao.support.DaoSupport dao ;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

 

package com.example.demo.config;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.jta.atomikos.AtomikosDataSourceBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import java.util.Properties;
/**
* 多数据源和Druid配置
*
* @author leilei
*/
@Configuration
public class DruidConfig {
/**
* 数据源1配置 使用AtomikosDataSourceBean 支持多数据源事务
*
* @param env
* @return Primary 指定主库 (必须指定一个主库 否则会报错)
*/
@Bean(name = "MybatisPlusOneDataSource")
@Primary
@Autowired
public AtomikosDataSourceBean oneDataSource(Environment env) {
AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
Properties prop = build(env, "spring.datasource.druid.one.");
ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
ds.setUniqueResourceName("oneDataSource");
ds.setPoolSize(5);
ds.setXaProperties(prop);
return ds;
}
/**
* 数据源2配置 使用AtomikosDataSourceBean 支持多数据源事务
*
* @param env
* @return
*/
@Autowired
@Bean(name = "MybatisPlusTwoDataSource")
public AtomikosDataSourceBean twoDataSource(Environment env) {
AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
Properties prop = build(env, "spring.datasource.druid.two.");
ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
ds.setUniqueResourceName("twoDataSource");
ds.setPoolSize(5);
ds.setXaProperties(prop);
return ds;
}
// @Autowired
// @Bean(name = "MybatisPlusThreeDataSource")
// public AtomikosDataSourceBean threeDataSource(Environment env) {
// AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
// Properties prop = build(env, "spring.datasource.druid.three.");
// ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
// ds.setUniqueResourceName("threeDataSource");
// ds.setPoolSize(5);
// ds.setXaProperties(prop);
// return ds;
// }
// /**
// * 注入事物管理器
// * @return
// */
// @Bean(name = "leijta")
// public JtaTransactionManager regTransactionManager () {
// UserTransactionManager userTransactiOnManager= new UserTransactionManager();
// UserTransaction userTransaction = new UserTransactionImp();
// return new JtaTransactionManager(userTransaction, userTransactionManager);
// }
/**
* 从配置文件中加载数据源信息
*
* @param env
* @param prefix
* @return
*/
private Properties build(Environment env, String prefix) {
Properties prop = new Properties();
prop.put("url", env.getProperty(prefix + "url"));
prop.put("username", env.getProperty(prefix + "username"));
prop.put("password", env.getProperty(prefix + "password"));
prop.put("driverClassName", env.getProperty(prefix + "driverClassName", ""));
prop.put("initialSize", env.getProperty(prefix + "initialSize", Integer.class));
prop.put("maxActive", env.getProperty(prefix + "maxActive", Integer.class));
prop.put("minIdle", env.getProperty(prefix + "minIdle", Integer.class));
prop.put("maxWait", env.getProperty(prefix + "maxWait", Integer.class));
prop.put("poolPreparedStatements", env.getProperty(prefix + "poolPreparedStatements", Boolean.class));
prop.put("maxPoolPreparedStatementPerConnectionSize",
env.getProperty(prefix + "maxPoolPreparedStatementPerConnectionSize", Integer.class));
prop.put("maxPoolPreparedStatementPerConnectionSize",
env.getProperty(prefix + "maxPoolPreparedStatementPerConnectionSize", Integer.class));
prop.put("validationQuery", env.getProperty(prefix + "validationQuery"));
prop.put("validationQueryTimeout", env.getProperty(prefix + "validationQueryTimeout", Integer.class));
prop.put("testOnBorrow", env.getProperty(prefix + "testOnBorrow", Boolean.class));
prop.put("testOnReturn", env.getProperty(prefix + "testOnReturn", Boolean.class));
prop.put("testWhileIdle", env.getProperty(prefix + "testWhileIdle", Boolean.class));
prop.put("timeBetweenEvictionRunsMillis",
env.getProperty(prefix + "timeBetweenEvictionRunsMillis", Integer.class));
prop.put("minEvictableIdleTimeMillis", env.getProperty(prefix + "minEvictableIdleTimeMillis", Integer.class));
prop.put("filters", env.getProperty(prefix + "filters"));
return prop;
}
/**
* druid访问配置
*
* @return
*/
@Bean
public ServletRegistrationBean druidServlet() {
ServletRegistrationBean servletRegistratiOnBean= new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
//控制台管理用户,加入下面2行 进入druid后台就需要登录
servletRegistrationBean.addInitParameter("loginUsername", "leilei");
servletRegistrationBean.addInitParameter("loginPassword", "123456");
return servletRegistrationBean;
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistratiOnBean= new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
filterRegistrationBean.addInitParameter("profileEnable", "true");
return filterRegistrationBean;
}
@Bean
public StatFilter statFilter() {
StatFilter statFilter = new StatFilter();
//slowSqlMillis用来配置SQL慢的标准,执行时间超过slowSqlMillis的就是慢。
statFilter.setLogSlowSql(true);
//SQL合并配置
statFilter.setMergeSql(true);
//slowSqlMillis的缺省值为3000,也就是3秒。
statFilter.setSlowSqlMillis(1000);
return statFilter;
}
@Bean
public WallFilter wallFilter() {
WallFilter wallFilter = new WallFilter();
//允许执行多条SQL
WallConfig cOnfig= new WallConfig();
config.setMultiStatementAllow(true);
wallFilter.setConfig(config);
return wallFilter;
}
}

 

package com.example.demo.config;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* @author : leilei
* @date : 14:20 2020/3/5
* @desc : 自定义异常响应
*/
@RestControllerAdvice
public class ExceptionHadler {
@ExceptionHandler(value = Exception.class)
public Map exceptionHandler(HttpServletRequest req, Exception e) {
HashMap map = new HashMap<>(4);
map.put("请求状态", "False");
map.put("请求路径", req.getRequestURI());
map.put("请求方式", req.getMethod());
map.put("错误信息", e.getMessage());
return map;
}
}

配置数据源1

package com.example.demo.config;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
/**
* @author leilei
*/
@Configuration
@MapperScan(basePackages = "com.example.demo.mapper.one", sqlSessiOnFactoryRef= "oneSqlSessionFactory")
public class OneDataSourceConfig {
@Primary
@Bean(name = "oneSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("MybatisPlusOneDataSource") DataSource dataSource) throws Exception {
//配置myabtisSqlSession
MybatisSqlSessionFactoryBean sessiOnFactoryBean= new MybatisSqlSessionFactoryBean();
// 指明mapper.xml位置(配置文件中指明的xml位置会失效用此方式代替,具体原因未知)
//sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/leilei/mapper/one/*/*Mapper.xml"));
// 指明实体扫描(多个package用逗号或者分号分隔)
sessionFactoryBean.setTypeAliasesPackage("com.example.demo.entity.one");
MybatisConfiguration mybatisCOnfiguration= new MybatisConfiguration();
// mybatisConfiguration.setJdbcTypeForNull(JdbcType.NULL);
//驼峰
mybatisConfiguration.setMapUnderscoreToCamelCase(true);
//是否开启缓存
mybatisConfiguration.setCacheEnabled(false);
//多数据源下分页模式
mybatisConfiguration.addInterceptor(new PaginationInterceptor());
// 配置打印sql语句
mybatisConfiguration.setLogImpl(StdOutImpl.class);
sessionFactoryBean.setConfiguration(mybatisConfiguration);
//数据源注入
sessionFactoryBean.setDataSource(dataSource);
return sessionFactoryBean.getObject();
}
@Primary
@Bean(name = "oneSqlSessionTemplate")
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("oneSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}

配置数据源2  需要几个就配置几个

package com.example.demo.config;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
/**
* @author leilei
*/
@Configuration
@MapperScan(basePackages = "com.example.demo.mapper.two", sqlSessiOnFactoryRef= "twoSqlSessionFactory")
public class TwoDataSourceConfig {
@Bean(name = "twoSqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("MybatisPlusTwoDataSource") DataSource dataSource) throws Exception {
//配置myabtisSqlSession
MybatisSqlSessionFactoryBean sessiOnFactoryBean= new MybatisSqlSessionFactoryBean();
// 指明mapper.xml位置(配置文件中指明的xml位置会失效用此方式代替,具体原因未知)
//sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:com/leilei/mapper/two/*/*Mapper.xml"));
// 指明实体扫描(多个package用逗号或者分号分隔)
sessionFactoryBean.setTypeAliasesPackage("com.example.demo.entity.two");
MybatisConfiguration mybatisCOnfiguration= new MybatisConfiguration();
//mybatisConfiguration.setJdbcTypeForNull(JdbcType.NULL);
//驼峰
mybatisConfiguration.setMapUnderscoreToCamelCase(true);
//是否开启缓存
mybatisConfiguration.setCacheEnabled(false);
//多数据源下分页模式
mybatisConfiguration.addInterceptor(new PaginationInterceptor());
// 配置打印sql语句
mybatisConfiguration.setLogImpl(StdOutImpl.class);
sessionFactoryBean.setConfiguration(mybatisConfiguration);
//数据源注入
sessionFactoryBean.setDataSource(dataSource);
return sessionFactoryBean.getObject();
}
@Bean(name = "twoSqlSessionTemplate")
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("twoSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}

 

package com.example.demo.controller;
import com.example.demo.service.ManySourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/hello")
public class ManySourceController {
@Autowired
ManySourceService manySourceService;
@GetMapping("/getZyBlock")
@ResponseBody
public String test1() {
return manySourceService.getZyBlock();
}
@GetMapping("/getYcUser")
@ResponseBody
public String test2() {
return manySourceService.getYcUser();
}
@PostMapping("/insertZyBlock")
@ResponseBody
public String test3() {
return manySourceService.insertZyBlock();
}
@PostMapping("/insertYcUser")
@ResponseBody
public String test4() {
return manySourceService.insertYcUser();
}
@PostMapping("/insertMany")
@ResponseBody
public String test5() {
return manySourceService.insertMany();
}
}

 

package com.example.demo.service;

import com.example.demo.entity.one.Block;
import com.example.demo.entity.two.User;
import com.example.demo.mapper.one.BlockMapper;
import com.example.demo.mapper.two.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ManySourceService {
//SpringBoot在使用事物Transactional的时候,要在main方法上加上 @EnableTransactionManagement
// 注解开发事物声明,在使用的service层的公共方法加上 @Transactional (spring)注解。
@Autowired
BlockMapper blockMapper;
@Autowired
UserMapper userMapper;
//获取zy库中的block中的数据
public String getZyBlock() {
return blockMapper.selectById("1").toString();
}
//获取yc库中的user中的数据
public String getYcUser() {
return userMapper.selectById("2").toString() ;
}
public String insertZyBlock() {
Block block = new Block();
block.setBlockId("99999");
block.setBlockName("PHP");
return blockMapper.insert(block)+"";
}
public String insertYcUser() {
User user = new User();
user.setUserId("2");
user.setName("李四");
return userMapper.insert(user)+"";
}
@Transactional
public String insertMany() {
Block block = new Block();
block.setBlockId("99999");
block.setBlockName("PHP");
blockMapper.insert(block) ;
int a = 100/0;
User user = new User();
user.setUserId("2");
user.setName("李四");
userMapper.insert(user) ;
return "1";
}
}

 

package com.example.demo.entity.one;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
/**
*


* 。
*


*
* @author yc
* @since 2021-09-18
*/
@TableName(value = "TEST_BLOCK_T")
public class Block {
private static final long serialVersiOnUID= 1L;
@TableId
private String blockId;
/**
* $field.comment。
*/
private String blockName;
public String getBlockId() {
return blockId;
}
public void setBlockId(String blockId) {
this.blockId = blockId;
}
public String getBlockName() {
return blockName;
}
public void setBlockName(String blockName) {
this.blockName = blockName;
}
@Override
public String toString() {
return "XyDicBlockT{" +
"blockId='" + blockId + '\'' +
", blockName='" + blockName + '\'' +
'}';
}
}

 

package com.example.demo.entity.two;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
/**
*


* 。
*


*
* @author yc
* @since 2021-09-18
*/
@TableName(value = "TEST_USER_T")
public class User {
private static final long serialVersiOnUID= 1L;
@TableId
private String userId;
/**
* $field.comment。
*/
private String name;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"userId='" + userId + '\'' +
", name='" + name + '\'' +
'}';
}
}

 

package com.example.demo.entity.two;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
/**
*


* 。
*


*
* @author yc
* @since 2021-09-18
*/
@TableName(value = "TEST_USER_T")
public class User {
private static final long serialVersiOnUID= 1L;
@TableId
private String userId;
/**
* $field.comment。
*/
private String name;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"userId='" + userId + '\'' +
", name='" + name + '\'' +
'}';
}
}

 

package com.example.demo.mapper.two;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.two.User;
public interface UserMapper extends BaseMapper {
}

 

 

 

 

 


6、启动项目访问项目

 

清空yc库里的表TEST_USER_T 和 zy库里的表TEST_BLOCK_T

 

(1)访问http://localhost:8080/hello/insertZyBlock 成功插入数据到TEST_BLOCK_T

(2)访问http://localhost:8080/hello/insertYcUser成功插入数据到TEST_USER_T

说明分别向不同数据源的数据库的插入没有问题。

(3)访问http://localhost:8080/hello/getZyBlock

 

 

 

(4)访问http://localhost:8080/hello/getYcUser

 

 

 

说明分别从不同数据源的数据库的查询没有问题。

 

再次清空yc库里的表TEST_USER_T 和 zy库里的表TEST_BLOCK_T

重头戏来了

(5)访问http://localhost:8080/hello/insertMany

 这里添加了事务,并且在插入TEST_BLOCK_T后制造了一个除数为0的错误,如果事务生效,前面插入的数据就应该回滚。

下面可以看到前台返回的消息报错了说了除数为0的错误。

 

后台开始也插入了数据,但是会发现数据库里并没有插入数据,说清事务生效了。

 

 



推荐阅读
  • 合并列值-合并为一列问题需求:createtabletab(Aint,Bint,Cint)inserttabselect1,2,3unionallsel ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • 本文介绍了iOS数据库Sqlite的SQL语句分类和常见约束关键字。SQL语句分为DDL、DML和DQL三种类型,其中DDL语句用于定义、删除和修改数据表,关键字包括create、drop和alter。常见约束关键字包括if not exists、if exists、primary key、autoincrement、not null和default。此外,还介绍了常见的数据库数据类型,包括integer、text和real。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • web.py开发web 第八章 Formalchemy 服务端验证方法
    本文介绍了在web.py开发中使用Formalchemy进行服务端表单数据验证的方法。以User表单为例,详细说明了对各字段的验证要求,包括必填、长度限制、唯一性等。同时介绍了如何自定义验证方法来实现验证唯一性和两个密码是否相等的功能。该文提供了相关代码示例。 ... [详细]
  • Python SQLAlchemy库的使用方法详解
    本文详细介绍了Python中使用SQLAlchemy库的方法。首先对SQLAlchemy进行了简介,包括其定义、适用的数据库类型等。然后讨论了SQLAlchemy提供的两种主要使用模式,即SQL表达式语言和ORM。针对不同的需求,给出了选择哪种模式的建议。最后,介绍了连接数据库的方法,包括创建SQLAlchemy引擎和执行SQL语句的接口。 ... [详细]
  • 本文主要复习了数据库的一些知识点,包括环境变量设置、表之间的引用关系等。同时介绍了一些常用的数据库命令及其使用方法,如创建数据库、查看已存在的数据库、切换数据库、创建表等操作。通过本文的学习,可以加深对数据库的理解和应用能力。 ... [详细]
  • 在Oracle11g以前版本中的的DataGuard物理备用数据库,可以以只读的方式打开数据库,但此时MediaRecovery利用日志进行数据同步的过 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • WebSocket与Socket.io的理解
    WebSocketprotocol是HTML5一种新的协议。它的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送 ... [详细]
  • Redis底层数据结构之压缩列表的介绍及实现原理
    本文介绍了Redis底层数据结构之压缩列表的概念、实现原理以及使用场景。压缩列表是Redis为了节约内存而开发的一种顺序数据结构,由特殊编码的连续内存块组成。文章详细解释了压缩列表的构成和各个属性的含义,以及如何通过指针来计算表尾节点的地址。压缩列表适用于列表键和哈希键中只包含少量小整数值和短字符串的情况。通过使用压缩列表,可以有效减少内存占用,提升Redis的性能。 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文介绍了如何使用JSONObiect和Gson相关方法实现json数据与kotlin对象的相互转换。首先解释了JSON的概念和数据格式,然后详细介绍了相关API,包括JSONObject和Gson的使用方法。接着讲解了如何将json格式的字符串转换为kotlin对象或List,以及如何将kotlin对象转换为json字符串。最后提到了使用Map封装json对象的特殊情况。文章还对JSON和XML进行了比较,指出了JSON的优势和缺点。 ... [详细]
author-avatar
5jkd_330
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有