public class SqlSessionDemo {
public static void main(String[] args) throws IOException {
String resouce = "config/mybatis-config.xml";
//读取配置文件
InputStream inputStream = Resources.getResourceAsStream(resouce);
//构建Session工厂
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//获取Session
SqlSession sqlSession = sqlSessionFactory.openSession();
VideoMapper videoMapper = sqlSession.getMapper(VideoMapper.class);
Video video = new Video();
video.setId(52);
video.setTitle("小滴课堂面试专题900道 2021年新版");
video.setCoverImg("xdclass.net/6666.png");
int rows = videoMapper.updateVideoSelective(video);
System.out.println(rows);
}
}
/**
* 动态选择更新
* @param video
* @return
*/
int updateVideoSelective(Video video);
update video
title = #{title,jdbcType=VARCHAR},
summary = #{summary,jdbcType=VARCHAR},
cover_img = #{coverImg,jdbcType=VARCHAR},
price = #{price,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
point = #{point,jdbcType=DOUBLE},
where
id = #{id}