zoukankan      html  css  js  c++  java
  • mybatis(4)使用注解方式配置sql语句

    使用注解方式配置sql语句,不需要写对应的UserMapper.xml

    package com.mapper;
    
    import java.util.List;
    
    import org.apache.ibatis.annotations.Delete;
    import org.apache.ibatis.annotations.Insert;
    import org.apache.ibatis.annotations.Select;
    import org.apache.ibatis.annotations.SelectKey;
    import org.apache.ibatis.annotations.Update;
    
    import com.pojo.User;
    
    //不需要写UserMapper的实现类
    public interface UserMapper {
        // 用于返回该条数据插入后的id
        @SelectKey(statement = "select last_insert_id()", before = false, keyProperty = "id", resultType = Integer.class)
        @Insert("insert into t_user (`last_name`,`sex`) values(#{lastName},#{sex})")
        public int saveUser(User user);
    
        @Delete("delete from t_user where id=#{id}")
        public int deleteById(Integer id);
    
        @Update(value = "update t_user set last_name=#{lastName},sex=#{sex} where id=#{id}")
        public int updateUser(User user);
    
        @Select("select id,last_name lastName,sex from t_user where id=#{id}")
        public User queryUserById(Integer id);
    
        @Select("select id,last_name lastName,sex from t_user")
        public List<User> queryUsers();
    }
  • 相关阅读:
    [转]趣题:一个n位数平均有多少个单调区间?---- From Matrix67
    2015编程之美复赛
    Codeforces Round #304 (Div. 2)
    HDU 5226
    HDU 5225
    HDU 3666
    HDU 4598
    Codeforces Round #303 (Div. 2) E
    编程之美初赛第二场AB
    2015 编程之美初赛第一场 AC题
  • 原文地址:https://www.cnblogs.com/ywqtro/p/12242692.html
Copyright © 2011-2022 走看看