Druid

MyBatis框架高级应用详解

眉间皱痕 提交于 2020-07-25 20:59:11
项目已托管到 GitHub ,大家可以去GitHub查看下载!并搜索关注微信公众号 码出Offer 领取各种学习资料! MyBatis 一、ORM概述 对象关系映射(Object Relational Mapping,简称ORM)是通过使用描述对象和数据库之间映射的元数据,将面向对象语言程序中的对象自动持久化到关系数据库中。本质上就是将数据从一种形式转换到另外一种形式。 ORM 二、ORM映射 2.1 MyBatis自动ORM失效 MyBatis只能自动维护库表“列名”与“属性名”相同时的一一对应关系,二者不同时,无法自动ORM。 自动ORM失效 007 2.2 解决方式一:列的别名 在SQL中使用 as 为查询字段添加列别名,以匹配属性名。 <mapper namespace= "com.mylifes1110.dao.ManagerDao" > <select id= "selectManagerByIdAndPwd" resultType= "com.mylifes1110.bean.Manager" > SELECT mgr_id AS id , mgr_name AS username , mgr_pwd AS password FROM t_managers WHERE mgr_id = #{id} AND mgr_pwd = #{pwd} </select> <

How add new column in to existing druid schema?

六眼飞鱼酱① 提交于 2020-06-13 01:29:08
问题 I create a schema and i add 1TB data to druid schema. then the log file version was upgraded and new two columns was added. then i want to add that data to druid schema. but couldn't yet. 回答1: In order to add a new column to existing datasource you need to follow the below steps: Go to the Tasks menu in druid console. From the listed datasources, go to the 'Actions' column in the last of the datasource in which you want to add the column. There will be a magnifying glass like button, click on

Spring整合SSM的配置文件详解

夙愿已清 提交于 2020-05-08 07:31:35
在整合三大框架SSM , 即 Spring 和 SpingMVC和Mybatis的时候,搭建项目最初需要先配置好配置文件. 有人在刚开始学习框架的时候会纠结项目搭建的顺序,因为频繁的报错提示是会很影响强迫症和编程心情的,这里分享我在构建项目时候的心得和配置文件的编写 首先你需要知道你的项目需要哪些结构,我们这里举一个基于Java的简单Web项目,实现最简单的功能,我需要Mybatis来进行持久层的控制,那么Mybatis就需要配置文件,我需要Dao层提供数据,那就需要Dao层的配置文件,我还需要服务层,那就需要Service的配置文件,再其次,我在进行一些选项的时候需要开启事务操作,那就需要事务的配置文件,最后是整合的SpringMVC的配置文件. 那么综上而言 我们把文件列表可以罗列出来: Mybatis的配置文件: sqlMapConfig.xml Spring的配置文件: applicationContext-dao.xml          applicationContext-service.xml          applicationContext-tx.xml          springmvc.xml 外部的Properties配置文件: jabc.properties 和 log4j.properties 学会配置xml文件是学习spring的基础

Springboot 系列(九)使用 Spring JDBC 和 Druid 数据源监控

二次信任 提交于 2020-05-07 13:36:42
前言 作为一名 Java 开发者,相信对 JDBC(Java Data Base Connectivity)是不会陌生的,JDBC作为 Java 基础内容,它提供了一种基准,据此可以构建更高级的工具和接口,使数据库开发人员能够编写数据库应用程序。下面演示下 Springboot 中如何使用 JDBC 操作,并配置使用 Druid 连接池,体验 Druid 对数据库操作强大的监控和扩展功能。Alibaba-Durid 官方手册 点这里 。 <!-- more --> 1. 数据库准备 使用mysql数据库创建数据库 springboot,并在库中新建数据表 user 并新增两条信息。 CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `age` int(11) DEFAULT NULL, `birthday` datetime DEFAULT NULL, `password` varchar(32) NOT NULL, `skills` varchar(255) DEFAULT NULL, `username` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; # 新增数据

springboot——数据层访问搭建 集成Duid连接池

守給你的承諾、 提交于 2020-05-07 10:55:46
springboot中默认是使用的tomcat的连接池,如果我们想要第三方的连接池,我们这么配置呢? 首先在application.yml文件中注释掉之前数据库的配置,重新用druid的方式配置: #spring: #datasource: # driver - class - name: com.mysql.jdbc.Driver # url: jdbc:mysql: // 127.0.0.1:3306/house #username: root #password: root mybatis.config -location = classpath:/mybatis/mybatis- config.xml spring.druid.url = jdbc:mysql: // 127.0.0.1:3306/house spring.druid.username = root spring.druid.password = root spring.druid.driverClassName = com.mysql.jdbc.Driver spring.druid.initialSize = 5 spring.druid.minIdle = 5 spring.druid.maxActive = 20 spring.druid.maxWait = 10000 spring.druid

第13章—数据库连接池(Druid)

拥有回忆 提交于 2020-05-07 10:55:20
spring boot 系列学习记录: http://www.cnblogs.com/jinxiaohang/p/8111057.html 码云源码地址: https://gitee.com/jinxiaohang/springboot   Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目。Druid支持所有JDBC兼容数据库,包括了Oracle、MySQL、PostgreSQL、SQL Server、H2等。   Druid在监控、可扩展性、稳定性和性能方面具有明显的优势。通过Druid提供的监控功能,可以实时观察数据库连接池和SQL查询的工作情况。使用Druid连接池在一定程度上可以提高数据访问效率。   Druid可以做什么? 可以监控数据库访问性能,Druid内置提供了一个功能强大的StatFilter插件,能够详细统计SQL的执行性能,这对于线上分析数据库访问性能有帮助。 替换 DBCP 和 C3P0 。Druid提供了一个高效、功能强大、可扩展性好的数据库连接池。 数据库密码加密。直接把数据库密码写在配置文件中,这是不好的行为,容易导致安全问题。DruidDruiver和DruidDataSource都支持PasswordCallback。 SQL执行日志,Druid提供了不同的LogFilter,能够支持 Common-Logging 、 Log4j

spring + Mybatis + pageHelper + druid 整合源码分享

和自甴很熟 提交于 2020-05-06 09:49:02
springMvc + spring + Mybatis + pageHelper + druid 整合 spring 和druid整合,spring 整合druid spring 和Mybatis 整合,spring 整合Mybatis Mybatis 和pageHelper 整合,Mybatis 整合pageHelper Mybatis和 druid整合,Mybatis整合druid Mybatis和 通用Mapper整合,Mybatis 通用Mapper Mybatis 整合 通用Dao ================================ ©Copyright 蕃薯耀 2018年3月16日 http://www.cnblogs.com/fanshuyao/ 本框架整合使用Maven方式构建,Jdk版本为JDK7,各插件版本如下: Xml代码 < spring.version >4.3.13.RELEASE </ spring.version > < mybatis.version >3.4.6 </ mybatis.version > < mybatis.spring.version >1.3.1 </ mybatis.spring.version > < mybatis.generator.version >1.3.6 </ mybatis.generator

spring与mybatis的整合

牧云@^-^@ 提交于 2020-05-06 08:46:32
整合的思路 SqlSessionFactory对象放到spring容器中作为单例存在。 传统dao的开发方式中,从spring容器中获得sqlsession对象。 Mapper代理形式中,从spring容器中直接获得mapper的代理对象。 数据库的连接以及数据库连接池事务管理都交给spring容器来完成。 整合需要的jar包 要实现spring与mybatis的整合,就要首先导入相关的依赖jar包,如下:   Spring的jar包   Mybatis的jar包   Spring与mybatis整合的jar包   Mysql数据库驱动的jar包   Druid数据库连接池的jar包   Spring与Junit集成测试的jar包(spring-test、Junit)   日志的jar包    具体依赖 < properties > < spring-version > 4.2.4.RELEASE </ spring-version > </ properties > < dependencies > <!-- spring 核心 --> < dependency > < groupId > org.springframework </ groupId > < artifactId > spring-context </ artifactId > < version > $

[Redis]

余生颓废 提交于 2020-05-05 01:46:48
rememberMe>>>>:null Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7398fa2] was not registered for synchronization because synchronization is not active JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5690c43b] will not be managed by Spring ==> Preparing: select id, name, password, salt from user where name = ? ==> Parameters: zhang3(String) < == Columns: id, name, password, salt < == Row: 5, zhang3, 7429017bd19cc345733399a2fb648cd7, +iaowhMUpqjV47c8Qma0Ng == < == Total: 1 Closing non transactional SqlSession [org.apache.ibatis

玩转Spring JUnit+mockito+powermock单元测试

最后都变了- 提交于 2020-05-02 20:16:34
Spring中执行单元测试,最麻烦的就是解决Bean的定义以及注入的问题。最开始使用Spring的上下文初始化进行测试,开头是这样的: @RunWith(SpringJUnit4ClassRunner. class ) @ContextConfiguration( "/config/Spring-db1.xml") 或者 @RunWith(SpringRunner. class ) // spring框架 @TestPropertySource(locations = "classpath:application-unittest-other.properties") // 配置文件 @ContextConfiguration( classes = TestServiceImplTest.MyConfiguration. class // 配置bean ) @TestConfiguration @ActiveProfiles( "unittest") // 激活对应配置文件 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) public class TestServiceImplTest { @Autowired TestApi testApi; // mock // ===