2021
01-21
01-21
老生常谈 MyBatis 复杂查询
一对一查询在实际开发中,经常会遇到一对一查询,一对多查询等。这里我们先来看一对一查询。例如:每本书都有一个作者,作者都有自己的属性,根据这个,我来定义两个实体类:publicclassBook{privateIntegerid;privateStringname;privateAuthorauthor;//省略getter/setter}publicclassAuthor{privateIntegerid;privateStringname;privateIntegerage;//省略getter/setter}然后,在数据库中,添加...
继续阅读 >
MyBatisGenerator命令生成1.下载jar:点击此处进入官网2.解压后打开lib在里面创建generatorConfig.xml和一个src文件夹。<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEgeneratorConfigurationPUBLIC"-//mybatis.org//DTDMyBatisGeneratorConfiguration1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration><!--数据库驱动--><!--选择自己的mysqljar包的版本--...
本博客主要用两个例子来说明一下批量删除和批量插入双层循环的用法,顺便自己记录一下,方便以后使用。1、批量删除(1):dao中的写法:publicintbatchDelPrice(@Param("deleteList")List<Map<String,Object>>deleteList);其中deleteList是一个Map的集合,Map中的Object是一个list集合,deleteList拼接如下:List<String>deletePriceId=getDelPriceId(oriPriceId,nowPriceId);Map<String,Object>deleteMap=newHashMap<Str...
异常org.springframework.jdbc.BadSqlGrammarException:###Errorupdatingdatabase.Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'INSERTINTOt_user_role(userid,roleid)VALUES(1,3);INSERTINTOt_user_ro'atline3###Theerrormayinvolvede...
前言通过Mybatis做7000+数据量的批量插入的时候报错了,errorlog如下:,('G61010352','610103199208291214','学生52','G61010350','610103199109920192','学生50','07','01','0104','',,'','',current_timestamp,current_timestamp)被中止,呼叫getNextException以取得原因。atorg.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2743)atorg.postgresql.cor...
环境配置1>先创建maven的quickstart项目;并且创建dao层,service层,controller层,po层,mapper,resources以及下面的配置文件(db.properties,log4j.properties,mybatis.xml,spring.xml).2>配置pom.xml修改jdk版本;添加依赖:junit版本改为4.12;spring-context;spring-test;spring-jdbc;spring-tx(事务);aspectjweaver(切面编程);c3p0(连接池);mybatis;mybatis-spring;mysql-connector-java(mysql驱动包)...
此问题的产生,主要是数据库的字段名一样导致三张表DOCTORJOBOBJECT有问题的查询语句和查询结果是:SELECTd.*,j.*,o.*from(selectd.*,rownumrfromDOCTORdwhererownum<=6)djoinjobjond.job_id=j.idjoinobjectoono.id=d.object_idwherer>0<imgsrc="https://img-blog.csdn.net/20161020110037608?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve...
Mybatis批量插入返回影响的行数环境:postgresql9.6.5spring4.1mybatis3junit4log4jThesisMapper.xml:<!--批量插入--><insertid="insertList"parameterType="java.util.List">insertintopublic.thesis(name)values<foreachcollection="list"item="t"index="index"separator=",">(#{t.name})</foreach></insert>Mapper.java借口:publicinterfaceThesisMapper{intinser...