动态sql <choose> </choose>

choose(when,otherwise):选择,类似java中的switch语句





    
        
        
    

    
    
package com.djx.mapper;

import com.djx.Blog;

import java.util.List;
import java.util.Map;

public interface BlogMapper {

     ListselectBrandChoose(Map map);
}

 

package com.djx.impl;

import com.djx.Blog;
import com.djx.mapper.BlogMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.security.spec.RSAOtherPrimeInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MybatisTest {
    public static void main(String[] args) throws IOException {
        /* 设置参数 **/
        int status = 1;
        String brandName = "华为";
        String companyName = "华为";

        /* 处理参数**/
        brandName = "%" + brandName + "%";
        companyName = "%" + companyName + "%";

        /*map集合参数**/
        Map map = new HashMap();
        map.put("status", status);
//        map.put("brandName", brandName);
//        map.put("companyName", companyName);
//        1
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//        2
        SqlSession session = sqlSessionFactory.openSession();
        BlogMapper mapper = session.getMapper(BlogMapper.class);
        
        List blog = mapper.selectBrandChoose(map);
//          3
        System.out.println(blog);
        session.close();
    }
}

你可能感兴趣的:(mybatis,sql,mybatis,java)