一.#{}方式
实现步骤:
- 在接口中声明方法
public interface FlowerMapper {
Flower selByIdName(int id,String name);
}
- 在mapper.xml中添加
<select id="selByIdName" resultType="flower">
select * from flower where id=#{0} and name=#{1}
</select>
二.注解方式
实现步骤:
- 在接口中声明方法
public interface FlowerMapper {
/**
* mybatis把参数转换为map,其中@Param("key")参数内容就是map的value
* @param id1
* @param name1
* @return
*/
Flower selByIdName(@Param("id") int id1,@Param("name") String name1);
}
- 在mapper.xml中添加
<select id="selByIdName" resultType="flower">
select * from flower where id=#{id} and name=#{name}
</select>