MyBatis常用注解

MyBatis常用注解:

       这是基于注解的映射方式,实现对数据的增删改查,将sql语句直接写在注解的括号中

这是一个接口,其不需要类去实现它

@Insert简单插入

@Insert("insert into student(name,age) values(#{name},#{age})")
public void addStudent(Student student) throws Exception;

@Upload简单修改

// 根据id修改姓名 ,方法的返回值代表修改的总数
@Update("update student set name = #{arg0} where id = #{arg1}")
public Integer updateNameById(String name, Integer id) throws Exception;

@Delete简单删除

// 根据id删除学生,方法的返回值代表删除的总数
@Delete("delete from student where id = #{id}")
public Integer deleteStudentById(Integer id) throws Exception;

@Select简单查询

 resultMap:

       将查询结果集合中的列一一映射到java对象的各个属性,常用于多表查询以及查询时使用别名的情况.

      当实体类跟表中属性名不一致,

在resultMap标签中做实体类中属性名和表中字段名之间的映射

       id:      当前resultMap映射结果

property:  实体类中属性名

column:   表中字段名称

 <resultMap type="java.util.Map" id="stuMap">
	 <result column="name" property="name"/>
	 <result column="age"  property="age"/>
 </resultMap>  
//resultMap:表示sql语句的查询结果类型对应哪一个映射关系
<select id="queryMulField2" resultMap="stuMap">
	 select id,age from student;
</select>
// 查询所有学生
@Select("select * from student")
  @Results({
       @Result(column = "name", property = "name"),
       @Result(column = "age", property = "age")
	   })
public List<Student> queryAllStudent() throws Exception;
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值