当前位置 博文首页 > Vicky_2020的博客:mybatis常用查询SQL总结
目录
1、普通查询
2、通过参数查询
3、通过对象查询
<select id="selectAll" resultMap="BaseResultMap">
select * from chart
</select>
(1)一个参数
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select * from chart
where id = #{id,jdbcType=INTEGER}
</select>
对应mapper
Chart selectByPrimaryKey(Integer id);
(2)多个参数
分页查询的例子:
<select id="findByPage" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select * from chart order by id asc limit #{startIndex},#{pageSize}
</select>
对应mapper,需要加上@Param注解
List<Chart> findByPage(@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);
多条件查询的例子:
<select id="selectByCondition" resultMap="BaseResultMap" parameterType="com.it.pojo.ChartCondition" >
select * from chart_type where 1=1 and
(<if test="typeId !=null | typeId!=''">
type_id= #{typeId}
</if>
<if test="typeName !=null| typeName!=''">
OR type_name= #{typeName}
</if>
<if test="createDate !=null">
OR create_date like concat(#{createDate}, '%')
</if>)
</select>
对应mapper
public List<Chart> selectByCondition(ChartCondition chartCondition);
cs