mybatis中的Criteria及对应xml的解析

Criteria的and和or进行联合查询

DemoExample example=new DemoExample ();
DemoExample.Criteria criteria=example.createCriteria();
criteria.andidEqualTo(id);
criteria.andStatusEqualTo("0");
        
DemoExample.Criteria criteria2=example.createCriteria();
criteria2.andidEqualTo(id);
criteria2.andstatusEqualTo("1");
example.or(criteria2);
dao.countByExample(example);

sql:select count(*) from demo WHERE ( ID = ? and STATUS = ? ) or( ID = ? and STATUS = ? )

xml中关于criteria的一些解读:




















and ${criterion.condition}



and ${criterion.condition} #{criterion.value}



and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}



and ${criterion.condition}

#{listItem}




















and ${criterion.condition}


and ${criterion.condition} #{criterion.value}


and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}


and ${criterion.condition}

#{listItem}











id, name, price, color, cima, imgPath








delete from g_good
where id = #{id,jdbcType=INTEGER}



delete from g_good






insert into g_good (id, name, price,
color, cima, imgPath
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=INTEGER},
#{color,jdbcType=VARCHAR}, #{cima,jdbcType=VARCHAR}, #{imgpath,jdbcType=VARCHAR}
)



insert into g_good


id,


name,


price,


color,


cima,


imgPath,




#{id,jdbcType=INTEGER},


#{name,jdbcType=VARCHAR},


#{price,jdbcType=INTEGER},


#{color,jdbcType=VARCHAR},


#{cima,jdbcType=VARCHAR},


#{imgpath,jdbcType=VARCHAR},







update g_good


id = #{record.id,jdbcType=INTEGER},


name = #{record.name,jdbcType=VARCHAR},


price = #{record.price,jdbcType=INTEGER},


color = #{record.color,jdbcType=VARCHAR},


cima = #{record.cima,jdbcType=VARCHAR},


imgPath = #{record.imgpath,jdbcType=VARCHAR},








update g_good
set id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
price = #{record.price,jdbcType=INTEGER},
color = #{record.color,jdbcType=VARCHAR},
cima = #{record.cima,jdbcType=VARCHAR},
imgPath = #{record.imgpath,jdbcType=VARCHAR}






update g_good


name = #{name,jdbcType=VARCHAR},


price = #{price,jdbcType=INTEGER},


color = #{color,jdbcType=VARCHAR},


cima = #{cima,jdbcType=VARCHAR},


imgPath = #{imgpath,jdbcType=VARCHAR},


where id = #{id,jdbcType=INTEGER}



update g_good
set name = #{name,jdbcType=VARCHAR},
price = #{price,jdbcType=INTEGER},
color = #{color,jdbcType=VARCHAR},
cima = #{cima,jdbcType=VARCHAR},
imgPath = #{imgpath,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}

你可能感兴趣的:(Java)