Mybatis
文章平均质量分 84
二十六画生的博客
国内Top5硕士,先后在京东、字节从事多年后端开发、大数据开发。
展开
-
Mybatis JDBC 事务隔离级别/脏读 不可重复读 幻读(虚读)
一般数据库的隔离级别有4个,由低到高依次为Read uncommitted、Read committed、Repeatable read、Serializable,这四个级别可以逐个解决脏读、不可重复读、幻读这几类问题。√: 可能出现×: 不会出现 脏读 不可重复读 幻读 说明 Read uncommitted √ √ √ 直译就是"读未提交",意思就是即使一个更新语句没有提交,但是别 的...转载 2021-01-19 11:45:35 · 1430 阅读 · 0 评论 -
Mybatis中Bind的用法
<sql id="columnSql"> <trim suffixOverrides=","> <!-- suffixOverrides此时的作用是去除最后一个逗号 --> id, username, password, sex, </trim></sql><select id="f原创 2018-02-26 16:34:35 · 9939 阅读 · 0 评论 -
Mybatis,String类型!=null,Integer类型!=null的实例
1 String类型!=null where 1=1 <if test="cityName !=null"> and city_name=#{cityName} </if>a: List<String> cityNameList = areaService.queryByTab...原创 2018-12-13 22:17:49 · 3084 阅读 · 0 评论 -
Mybatis,String类型条件的字符串需要带单引号
cityName是String类型List<String> cityNameList = areaService.queryByTableType(new AreaQO("忻州")); <select id="queryByTableType" resultType="String" parameterType="AreaQO"> select原创 2018-12-13 22:24:38 · 6938 阅读 · 0 评论 -
Mybatis根据条件使用不同的表
<select id="queryByTableType" resultType="String" parameterType="AreaQO"> select city_name from <if test="tableType == 1"> area_table原创 2018-12-13 22:28:31 · 8774 阅读 · 1 评论 -
Mysql复合索引,条件中有or时使用不到
建表语句的sql片段: KEY `c_d_e_f` (`c`,`d`,`e`,`f`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='XXXXXXX';查询语句selectc1,c2,c3fromt1WHERE (a = 'xxa' or b = 'xxb' )and c='xxc'and d...原创 2018-12-22 09:32:05 · 3904 阅读 · 0 评论 -
Mybatis使用自定义方法判断参数的条件
1 如下,不会报错,但是if判断不出来,sql中不包含该条件 <if test="orderColumn.length ==1"> ... </if> 或者 <if test="orderColumn.length < 1"> ...原创 2018-12-25 20:21:31 · 2347 阅读 · 0 评论 -
Mybatis条件if test使用枚举值
1 正确package com.weather.weatherexpert.common.utils;/** * <p>Title: </p> * <p>Description: </p> * * @Author * @CreateTime */public enum City { XINZHOU(100002...原创 2019-01-15 12:51:12 · 12545 阅读 · 5 评论 -
Mybatis使用常量判断参数的条件
xml:<if test="timeType == @com.a.b.c.SystemConst@TIME_TYPE_WEEK">...</if>同时:public class SystemConst { public static final String TIME_TYPE_WEEK = "week";这样即能使用常量TIME_...原创 2019-01-09 22:08:01 · 3609 阅读 · 0 评论 -
Mybatis中不能使用非静态方法,不能使用非静态变量,OGNL表达式用法
1Mybatis中使用非静态方法会报错package com.weather.weatherexpert.common.utils;/** * @Desc * @Author liuyazhou * @CreateTime 2018/6/13 21:01 **/public class StringUtils { public boolean isNotBlank(S...原创 2019-01-16 22:02:05 · 2273 阅读 · 0 评论 -
@Param作用,MyBatis的注解
@Param的作用就是定义输入参数的别名,在SQL语句中可以使用参数别名。亲测能够正确查询结果原创 2018-02-03 17:13:40 · 1395 阅读 · 0 评论 -
Mybatis,foreach用法--对于list和array
foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合。foreach元素的属性主要有 item,index,collection,open,separator,close。 item表示集合中每一个元素进行迭代时的别名, index指定一个名字,用于表示在迭代过程中,每次迭代到的位置, open表示该语句以什么开始, separa原创 2018-02-04 15:43:11 · 24596 阅读 · 1 评论 -
MyBatis批量插入对象
/** * 新记录插入cms_role_menu * @param cmsRoleMenuList * @return */ int insertCmsRoleMenu(List cmsRoleMenuList); insert into cms_role_menu ( role_id,原创 2017-10-23 21:34:55 · 5346 阅读 · 0 评论 -
SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
这个问题是解决以下问题出现的:java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp问题原因是因为JDBC url=jdbc:mysql://xxx.aliyuncs.com:3306/xxxxx?useUnicode=true&characterEn转载 2018-01-05 21:59:43 · 308 阅读 · 0 评论 -
根据建表语句生成实体类和查询用的ResultMap
import java.io.*;public class Main { public static void main(String[] args) { String filePath = "D:\\00t1.txt"; Main main = new Main(); main.getModel(filePath);原创 2018-01-15 22:17:21 · 1694 阅读 · 1 评论 -
Mybatis <where>用法
<select id="findUserInfoByUnoQuantity" parameterType="Map" resultMap="UserInfoResult"> select * from userinfo department like #{department}转载 2018-02-02 16:13:29 · 9902 阅读 · 0 评论 -
MyBatis传入参数的方式
以下是传入两个参数的方式:第一种,使用@Param注解,定义参数别名,即定义映射关系DAO: public List findByUsernameAndPwd(@Param("userNameABC") String username, @Param("passWordDEF") String password);SQL: SELECT FROM t_user原创 2018-02-03 17:42:27 · 1203 阅读 · 0 评论 -
NodeletException: Error parsing XML. Error parsing XPath '/sqlMap/update'. NoSuchElementException
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/update'. Cause: java.util.NoSuchElementExceptionat com.iba原创 2018-01-28 15:51:25 · 4451 阅读 · 0 评论 -
iBatis查询,isNotEmpty不起作用,解决方法
iBatis查询,isNotEmpty不起作用,解决方法:property别忘了写,修改成如下: select * from table where 1 =1 id =]]> #fromId# id #toId# order by原创 2018-01-09 15:43:56 · 4713 阅读 · 0 评论 -
SQLException: Access denied for user 'root'@'localhost' (using password: YES)解决方法
我本地用cmd,输入同样的用户名和密码能正确登录,web却不行。找了很久都不行。最后在cmd上修改了mysql密码,果然行了,有些奇怪。报错如下:修改mysql密码:原创 2018-01-30 09:45:04 · 1015 阅读 · 0 评论 -
MyBatis的where,trim,prefix,prefixOverrides,suffixOverrides使用实例
建表语句和表的数据,以及范例如下:第1种:直接使用where id, username, password, sex, SELECT FROM t_user WHERE username = #{username} and password = #{password}输入:username:Tom,password:1232018原创 2018-02-04 12:02:45 · 8743 阅读 · 1 评论 -
MyBatis批量删除
/** * 根据主键删除数据库的记录,cms_menu * * @param idList */ int deleteByPrimaryKey(List idList); delete from cms_menu where id in原创 2017-10-23 21:32:03 · 4990 阅读 · 1 评论