1. 程式人生 > >mybatis學習記錄~

mybatis學習記錄~

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)