mybatis注解进行增删改查
dao
package com.lyh.Dao;
import com.lyh.pojo.User;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface UserDao {
@Select("select * from hadoop.user")
List<User> getUserList();
@Select("select * from hadoop.user where id = #{id} and name like CONCAT('%',#{name},'%') ")
List<User> findAll(@Param("id") int id, @Param("name") String name);
@Insert("insert into user values(#{id},#{name},#{pwd})")
void addUser(@Param("id") int id, @Param("name") String name, @Param("pwd") String pwd);
@Update("update hadoop.user set name = #{name} where id = #{id}")
void updateUser(@Param("name") String name, @Param("id") int id);
@Delete("delete from hadoop.user where id = #{id}")
void deleteUser(@Param("id") int id);
}
mybatis-config
<mappers>
<mapper class="com.lyh.Dao.UserDao"/>
</mappers>
|