MyBatis_1 单表注解 和简单的查询

项目与工程一对多,主要实现使用注解在项目的mapper中对工程进行简单的单表操作    
// 1.项目mapper插入工程表数据 @注解
@Insert("INSERT INTO `jsy`.`t_eng` (`p_id`, `e_id`, `e_name`, `e_content`, `e_num`) VALUES (#{pId}, #{eId}, #{eName}, #{eContent}, #{eNum});")
int insertEngByAnnotation(TEng e);
// 2.*单删* 1.使用 @注解
@Delete("delete from t_eng where e_id = #{eId}")
int deleteEngByEngId(String eId);
// 3.*单查* 使用 1.@注解 通过id查询
@Select("select * from t_eng where e_id = #{eId}")
TEng selectEngByEngId(String eId);//可以查询几个字段
// 4.*单改* 使用 1.@注解 以对象的形式修改
@Update("UPDATE t_eng SET e_name = #{eName}, e_content = #{eContent} WHERE e_id =#{eId} ")
int updateEng(TEng e);
//5.本人没有实现在 项目(projectMapper)中 以字段的方式修改 工程(Eng)表,报错字段对应问题

//1.使用 in 查询 dao
List selectIn(@Param("lList") List list);
//xml
<select id="selectIn" parameterType="java.util.List" resultType="java.util.Map">
    select * from a_group where g_id in
    <foreach collection="lList" index="index" item="item" open="(" separator="," close=")">  
        #{item}  
    </foreach>
</select>

// 2.在map中存在value为list
Map m = new HashMap<String,Object>();
m.put("gidList", list);
m.put("gName", "002项目工程8543工程338");
List result = aProjectMapper.selectByListAndName(m);
//xml
<select id="selectByListAndName" parameterType="java.util.Map" resultType="java.util.Map">
    select * from a_group where g_id in
    <foreach collection="gidList" index="index" item="item" open="(" separator="," close=")">  
        #{item}  
    </foreach>
    or g_name = #{gName}   
</select>

猜你喜欢

转载自blog.csdn.net/qq_41859067/article/details/83662878