mybatis04-基于注解开发

有四个注解
@select @insert @update @delete

image

package com.kcl.dao;

import com.kcl.pojo.User;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 项目名: mybatis_heima_01
 * 包名:    com.kcl
 * 文件名   UserDao
 * 创建者
 * 创建时间: 2022/4/2 11:29 PM
 * 描述  用户持久层接口
 */
public interface UserDao {


    @Select("select * from user")
    List<User> findAllUser();

    @Insert("insert into user(username,address,sex,birthday) values (#{username},#{address},#{sex},#{birthday})")
    void saveUser(User user);

    @Update("update user set username = #{username},address = #{address},sex=#{sex},birthday=#{birthday} where id = #{id}")
    void updateUser(User user);

    @Delete("delete from user where id = #{id}")
    void deleteById(Integer id);
    
    @Select("select * from user where id = #{id}")
    User getById(Integer id);
    
    //使用: findUserByName("%王%");
    @Select("select * from user where username like #{username}")
    List<User> findUserByName(String username);
    
    @Select("select count(*) from user")
    int getCount();
}
posted @ 2022-04-03 13:13  超级氯化钾  阅读(37)  评论(0)    收藏  举报