Mybatis注解@Insert、@Select、 @Update 、@Delete 用法示例

参考文章:https://blog.csdn.net/u013452337/article/details/100693418

@Insert :@InsertProvider

@Select :@SelectProvider

@Update :@UpdateProvider

@Delete :@DeleteProvider

@Select

@Select("select * from t_emp")

@Select("select * from t_emp where emp_id=#{empId}")

@ResultMap(value="empMap")

Employee getById(@Param("empId") Integer empId);

@Delete

@Delete("delete from t_emp where emp_id=#{empId}")

int deleteByPrimaryKey(@Param("empId") Integer empId);

@Update

@Update("update t_emp" +

" set emp_name = #{empName,jdbcType=VARCHAR}," +

" emp_tel = #{empTel,jdbcType=VARCHAR}," +

" emp_education = #{empEducation,jdbcType=VARCHAR}," +

" emp_birthday = #{empBirthday,jdbcType=DATE}," +

" fk_dept_id = #{fkDeptId,jdbcType=INTEGER}" +

" where emp_id = #{empId,jdbcType=INTEGER}")

int update(Employee record);

@Insert

@Insert("insert into t_emp (emp_id, emp_name, emp_tel, " +

" emp_education, emp_birthday, fk_dept_id" +

" )" +

" values (#{empId}, #{empName}, #{empTel}, " +

" #{empEducation}, #{empBirthday}, #{fkDeptId}" +

" )")

@SelectKey(before = false,keyColumn = "emp_id",keyProperty = "empId",

statement = "select last_insert_id()",resultType = Integer.class)

int insert(Employee record);

 

你可能感兴趣的:(mysql,mybatis,sql,java,数据库)