vue任意關係元件通訊與跨元件監聽狀態 vue-communication
阿新 • • 發佈:2020-10-18
<!--資料動態sql處理 --> <select id="dynamicSql" parameterType="java.util.Map" resultType="com.imooc.mybatis.entity.GoodsEntity"> <!--編寫sql--> select * from t_goods <where> <!--test中是javabean的屬性判斷--> <iftest="categoryId != null"> and category_id = #{categoryId} </if> <if test="currentPrice !=null"> <!-- < < > > & & --> and current_price < #{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); } }