mapper

spring mybatis

两盒软妹~` 提交于 2019-12-06 02:12:31
getBeanPostProcessors()就是所有的后置处理器,就是拦截器,就是责任链模式。 ## 数据源配置 spring.datasource.url=jdbc:mysql://localhost:3306/upgrade?useUnicode=true&characterEncoding=utf8 spring.datasource.username=root spring.datasource.password= spring.datasource.driver-class-name=com.mysql.jdbc.Driver ## Mybatis 配置 mybatis.typeAliasesPackage=com.hcxy.car.bean mybatis.mapperLocations=classpath:mapper/*.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="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 http://maven.apache.org

org.springframework.beans.factory.BeanCreationException

限于喜欢 提交于 2019-12-06 01:57:40
一. 报错原因 : Cause: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 83; 文档根元素 "mapper" 必须匹配 DOCTYPE 根 "null"。 引起:mapper中缺少<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 解决:加上缺少的表头就可以了。 二.报错原因: Cause: org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 10; 元素类型为 "mapper" 的内容必须匹配 "(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*)+"。 引起:我也不知道为什么,重新都手打了一遍就好了 来源: https://www.cnblogs.com/jinaokaifa/p/11955855.html

What is the `connection` parameter of MapperExtension in sqlalchemy?

◇◆丶佛笑我妖孽 提交于 2019-12-05 22:54:41
The class MapperExtension has some methods, and before_insert , before_update , ... all have a parameter connection . def before_insert(self, mapper, connection, instance): I've read the documents of MapperExtension , but found nothing about this connection . What is it? And how to use it? Denis Otkidach It's an instance of Connection class . Recent versions of SQLAlchemy distribution have examples directory, see examples/nested_sets/nested_sets.py to get an idea on how to use it in mapper extension. 来源: https://stackoverflow.com/questions/3646773/what-is-the-connection-parameter-of

SSM生成逆向工程

十年热恋 提交于 2019-12-05 22:15:23
1.pom.xml将pom中的build替换成一下代码 <build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.7</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies><dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency></dependencies> </plugin> </plugins> </build> 2.在resources包里加入generatorConfig.xml,注意将 targetProject=".\src\main\java的对应路径名进行更改 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration

MyBatis sql映射器 Mapper

半腔热情 提交于 2019-12-05 20:56:03
入门   MyBatis 基于动态代理机制,让我们无需再编写 Dao 的实现。    传统 Dao 接口,现在名称统一以 Mapper 结尾 , 还有我们映射器配置文件要和映射器在同一个包 . :   IDeptDao---->DeptMapper.java---DeptMapper.xml(namespace 直接写 DeptMapper.java 的全限定名 ) 1.创建个 User 类(首先得有个数据库中的表是User,并且还有对应的字段) public class User { private Long id; private String name; get和set和tostring此处省略。。。。(get和set和tostring是要的,太长了没复制) } 2.个上面的类建个接口 UserMapper import java.util.List; /** * 查询数据库中所有数据 * @return */ public interface UserMapper {   List<User> queryAll(); } 3.建个 UserMapper.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http:/

springboot整合mybatis

陌路散爱 提交于 2019-12-05 20:47:44
1、springboot 配置数据库连接池 druid 2、springboot 整合 mybatis 3、springboot 整合 pagehelper springboot 配置数据库连接池 druid 新建 springboot 项目 相关 pom 依赖 druid 所需 pom 依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> 配置 application.yml spring: datasource: #1.JDBC type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/book?useUnicode=true&characterEncoding=utf8 username: root password: 123 druid: #2.连接池配置 #初始化连接池的连接数量 大小,最小,最大 initial-size: 5 min-idle: 5 max-active:

MyBatis进阶讲解+ssm集成

最后都变了- 提交于 2019-12-05 20:46:02
1.sql映射器Mapper MyBatis基于动态代理机制,让我们无需再编写Dao的实现。 传统Dao接口,现在名称统一以Mapper结尾,还有我们映射器配置文件要和映射器在同一个包。 1.1使用映射器步骤: (1)根据需求,创建模型相关的Mapper接口 (2)编写映射文件   a)*Mapper.xml的命名空间,必须和接口的“全限定名”一致   b)定义sql标签的id,需要和“接口的方法”一致 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 4 <mapper namespace="cn.itsource._01_mapper.TeacherMapper"> 5 <!-- 查询 findAll() 6 resultType 返回类型 7 --> 8 <select id="findAll" resultType="Teacher"> 9 select * from t_teacher 10 </select> 11 </mapper> (3)测试 1 @Test 2 public void findAll() { 3

ssm项目集成

只谈情不闲聊 提交于 2019-12-05 20:15:00
ssm项目集成 说明:ssm指的是 spring + springMvc+ mybatis,是目前开发比较流行的集成方式,可以较好的实现前后端分离 spring与mybatis的集成,是通过配置文件applicaContext.xml实现的,其中将mybatis的核心对象SqlSessionFactory通过工厂创建bean对象的方法注入到spring容器中 这样就不需要使用new的方式创建对象,步骤简单,底层帮忙实现其中的mapper对象的封装,mapper对象使我们操作数据库的最终对象。 springmvc+spring 的集成:配置web.xml,在启动服务器的时候会读取web.xml文件,在读取的时候监听spring容器,加载spring核心配置文件和启动springMvc容器,加载springMvc核心配置文件,最后配置过滤器,解决编码问题。 步骤: 1. 创建一个maven或者普通的web项目 使用ider'或者eclipse创建一个web项目(该结构就不再赘述) 2.导包 导包完成后,build path 或者 addlibary 解析,如果是maven项目,则在pop.xml 写依赖即可 3.写配置文件 1.写spring的核心配置文件:applicationContext.xml <!--加载配置文件--> <context:property

Mybatis batch 批量处理

旧时模样 提交于 2019-12-05 19:52:17
@Testpublic void batch() throws IOException { InputStream inputStream= Resources.getResourceAsStream("mybatis-config.xml"); //读取mybatis 配置文件创建sqlsessionFactory SqlSessionFactory sqlSessionFactory= new SqlSessionFactoryBuilder().build(inputStream); inputStream.close(); //获取sqlsession SqlSession sqlSession=sqlSessionFactory.openSession(ExecutorType.BATCH,false); //默认 single //获取对应mapper userMapper mapper=sqlSession.getMapper(userMapper.class); user userobj1=new user(); userobj1.setId(1); userobj1.setName("11"); mapper.insert(userobj1); user userobj2=new user(); userobj2.setId(1); userobj2