mybatis注解形式操作数据
注解代码:
import java.util.List; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.type.Alias; public interface UserMapper { @Select("SELECT * FROM user ") List<User> selectAllUser(); }
mybatis-config.xml中配置mapper
<mappers> <mapper resource="com/ibatis/pojo/user.xml" /> <!--xml形式映射 --> <mapper class="com.ibatis.pojo.UserMapper" /> <!--注解形式映射 或者 代码中手动加载:ssf.getConfiguration().
addMapper(UsergMapper.class);--> </mappers>
java代码:
BlogMapper mapper = session.getMapper(BlogMapper.class);