mybatis:insert插入记录xml写法

insert插入记录
测试类:

@Test
public void testinsert(){
    SqlSession session = MyBatisUtil.getSqlSession();
    BlogMapper blogMapper= session.getMapper(BlogMapper.class);
    Blog blog=new Blog(101,"代码猪,"爱吃",20000.0);
    int count= blogMapper.insert(blog);
    session.commit();
    session.close();
    System.out.println(count);
}

BlogMapper 接口:

public interface BlogMapper {
    int insert(Blog blog);
}    

BlogMapper.xml:





	
	
	    INSERT INTO  blog(
	    zwid,flname,zhangHu,money
	    )VALUES (
	      #{zwid},
	      #{name},
	      #{zhangHu},
	      #{money}
	    )
	


parameterType=“Blog
指的是返回值类型为“Blog”。这里直接写的类名,一般应该写全路径名(com.hd.mybatis.pojo.Blog),在mybatis-config.xml设置以下配置后,直接写类名即可。
mybatis-config.xml:

    
      
	    
    

你可能感兴趣的:(Mybatis)