一、创建Maven工程并编辑pom.xml
pom.xml
4.0.0 mabatis_v1.0 mabatis_v1.0 0.0.1-SNAPSHOT war src maven-compiler-plugin 3.3 maven-war-plugin 2.6 WebContent false org.mybatis mybatis 3.2.8 junit junit 4.10
二、创建java类
三、创建java对象与数据库之间的xml文件
NewsMapper.xml
and ${criterion.condition} and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{listItem} and ${criterion.condition} and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{listItem} newsID, newsType, newsTitle, newsWriter, newsTime newsContent delete from news_tb where newsID = #{newsid,jdbcType=INTEGER} delete from news_tb insert into news_tb (newsID, newsType, newsTitle, newsWriter, newsTime, newsContent ) values (#{newsid,jdbcType=INTEGER}, #{newstype,jdbcType=VARCHAR}, #{newstitle,jdbcType=VARCHAR}, #{newswriter,jdbcType=VARCHAR}, #{newstime,jdbcType=TIMESTAMP}, #{newscontent,jdbcType=LONGVARCHAR} ) insert into news_tb newsID, newsType, newsTitle, newsWriter, newsTime, newsContent, #{newsid,jdbcType=INTEGER}, #{newstype,jdbcType=VARCHAR}, #{newstitle,jdbcType=VARCHAR}, #{newswriter,jdbcType=VARCHAR}, #{newstime,jdbcType=TIMESTAMP}, #{newscontent,jdbcType=LONGVARCHAR}, update news_tb newsID = #{record.newsid,jdbcType=INTEGER}, newsType = #{record.newstype,jdbcType=VARCHAR}, newsTitle = #{record.newstitle,jdbcType=VARCHAR}, newsWriter = #{record.newswriter,jdbcType=VARCHAR}, newsTime = #{record.newstime,jdbcType=TIMESTAMP}, newsContent = #{record.newscontent,jdbcType=LONGVARCHAR}, update news_tb set newsID = #{record.newsid,jdbcType=INTEGER}, newsType = #{record.newstype,jdbcType=VARCHAR}, newsTitle = #{record.newstitle,jdbcType=VARCHAR}, newsWriter = #{record.newswriter,jdbcType=VARCHAR}, newsTime = #{record.newstime,jdbcType=TIMESTAMP}, newsContent = #{record.newscontent,jdbcType=LONGVARCHAR} update news_tb set newsID = #{record.newsid,jdbcType=INTEGER}, newsType = #{record.newstype,jdbcType=VARCHAR}, newsTitle = #{record.newstitle,jdbcType=VARCHAR}, newsWriter = #{record.newswriter,jdbcType=VARCHAR}, newsTime = #{record.newstime,jdbcType=TIMESTAMP} update news_tb where newsID = #{newsid,jdbcType=INTEGER} newsType = #{newstype,jdbcType=VARCHAR}, newsTitle = #{newstitle,jdbcType=VARCHAR}, newsWriter = #{newswriter,jdbcType=VARCHAR}, newsTime = #{newstime,jdbcType=TIMESTAMP}, newsContent = #{newscontent,jdbcType=LONGVARCHAR}, update news_tb set newsType = #{newstype,jdbcType=VARCHAR}, newsTitle = #{newstitle,jdbcType=VARCHAR}, newsWriter = #{newswriter,jdbcType=VARCHAR}, newsTime = #{newstime,jdbcType=TIMESTAMP}, newsContent = #{newscontent,jdbcType=LONGVARCHAR} where newsID = #{newsid,jdbcType=INTEGER} update news_tb set newsType = #{newstype,jdbcType=VARCHAR}, newsTitle = #{newstitle,jdbcType=VARCHAR}, newsWriter = #{newswriter,jdbcType=VARCHAR}, newsTime = #{newstime,jdbcType=TIMESTAMP} where newsID = #{newsid,jdbcType=INTEGER}
四、创建confg.xml文件
五、创建SqlSessionFactory,获取session