Java67
Posted 码农编程录
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java67相关的知识,希望对你有一定的参考价值。
1.CheckItemMapper.java
package com.itheima.mapper;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface CheckItemMapper {
void add(CheckItem checkItem);
List<CheckItem> findByCondition(@Param("queryString") String queryString);
Integer findCountByCheckItemId(@Param("id")Integer id);
void deleteById(@Param("id")Integer id);
CheckItem findById(@Param("id")Integer id);
void edit(CheckItem checkItem);
List<CheckItem> findAll();
List<Integer> findCheckItemIdsByCheckGroupId(@Param("checkGroupId")Integer checkGroupId);
/***
* 只要参数不是pojo\\Map都使用@Param
*
* @param queryString
* @return
*/
// Long findCount(@Param("queryString") String queryString);
// List<CheckItem> findByCondition(@Param("firstResult")int firstResult, @Param("pageSize")Integer pageSize, @Param("queryString")String queryString);
}
CheckItemMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.CheckItemMapper">
<insert id="add">
insert into t_checkitem values(null,#{code},#{name},#{sex},#{age},#{price},#{type},#{attention},#{remark})
</insert>
<!--条件查询总记录数-->
<!-- <select id="findCount" resultType="Long">
select count(id) from t_checkitem
<if test="queryString!=null and queryString.trim()!=''">
where code = #{queryString} or name like "%" #{queryString} "%"
</if>
</select>-->
<!--查询分页数据-->
<!--<select id="findByCondition" resultType="CheckItem">
select * from t_checkitem
<if test="queryString!=null and queryString.trim()!=''">
where code = #{queryString} or name like "%" #{queryString} "%"
</if>
limit #{firstResult},#{pageSize}
</select>-->
<select id="findByCondition" resultType="CheckItem">
select * from t_checkitem
<if test="queryString!=null and queryString.trim()!=''">
where code = #{queryString} or name like "%" #{queryString} "%"
</if>
</select>
<!--通过id统计当前检查项是否被引用过-->
<select id="findCountByCheckItemId" resultType="Integer">
select count(checkitem_id) from t_checkgroup_checkitem where checkitem_id = #{id}
</select>
<!--通过id删除检查项-->
<delete id="deleteById">
delete from t_checkitem where id = #{id}
</delete>
<!--通过id查询检查项-->
<select id="findById" resultType="CheckItem">
select * from t_checkitem where id = #{id}
</select>
<!--编辑更新-->
<update id="edit">
update t_checkitem
<set>
<if test="code !=null">
code = #{code},
</if>
<if test="name !=null">
name = #{name},
</if>
<if test="sex !=null">
sex = #{sex},
</if>
<if test="age !=null">
age = #{age},
</if>
<if test="price !=null">
price = #{price},
</if>
<if test="type !=null">
type = #{type},
</if>
<if test="attention !=null">
attention = #{attention},
</if>
<if test="remark !=null">
remark = #{remark}
</if>
</set>
where id = #{id}
</update>
<!--查询所有检查项-->
<select id="findAll" resultType="CheckItem">
select * from t_checkitem
</select>
<select id="findCheckItemIdsByCheckGroupId" resultType="Integer">
select checkitem_id from t_checkgroup_checkitem where checkgroup_id = #{checkGroupId}
</select>
<select id="findCheckItemByCheckGroupId" resultType="CheckItem">
select * from t_checkitem where id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{checkGroupId})
</select>
</mapper>
以上是关于Java67的主要内容,如果未能解决你的问题,请参考以下文章