1. 程式人生 > 實用技巧 >軟體測試質量保障之開發提測

軟體測試質量保障之開發提測

        <!--資料動態sql處理 -->
        <select id="dynamicSql" parameterType="java.util.Map" resultType="com.imooc.mybatis.entity.GoodsEntity">
            <!--編寫sql-->
            select * from t_goods
            <where>
                <!--test中是javabean的屬性判斷-->
                <if
test="categoryId != null"> and category_id = #{categoryId} </if> <if test="currentPrice !=null"> <!-- < &lt > &gt & &amp --> and current_price &lt; #{currentPrice}
</if> </where> </select>
    public void DynamicSql() throws Exception {
        SqlSession sqlSession = null;
        try {
            //獲取sql物件
            sqlSession = MybatisUtils.openSession();
            //例項化goods,插入資料
            Map map = new HashMap();
            map.put(
"categoryId",43); map.put("currentPrice",200f); //執行sql List<GoodsEntity> list = sqlSession.selectList("goods.dynamicSql",map); //提交資料 sqlSession.commit(); System.out.println(list); //檢視連線狀態 Connection conn = MybatisUtils.getConnection(sqlSession); }catch (Exception e){ sqlSession.rollback();//資料回滾 throw e; }finally { MybatisUtils.release(sqlSession); } }