mybatis學習記錄~
阿新 • • 發佈:2018-12-30
mybatis版本
<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.6</version> </dependency>
動態SQL語句
IF標籤
<select id="findSelective" parameterType="com.tsing.model.Blog" resultMap="BaseResultMap"> SELECT * FROM blog WHERE `status` = 1 <if test="title != null and title != '' "> and title like #{title} </if> <if test="summary != null "> and summary like #{summary}</if> </select>
@Test public void testFindSelective() { SqlSessionFactory factory = DataBaseTools.getSqlSessionFactory(); SqlSession session = factory.openSession(true); BlogMapper mapper = session.getMapper(BlogMapper.class); Blog blog= new Blog(); blog.setTitle(""); blog.setSummary(""); mapper.findSelective(blog) ; }
日誌輸出
==> Preparing: SELECT * FROM blog WHERE `status` = 1 and summary like ?
==> Parameters: (String)