笔记要点
出错分析与总结
更推荐,原生的sql写法,bind方法不灵活! Test中: e.setLastName("%e%"); 直接在这里写上模糊查询的语句,更加省时 配置中: 不用bind!
1.定义接口
public List<Employee> getEmpsTestInnerParameter(Employee employee);//测试内部参数
2.定义XML映射文件
@Test public void test11() throws Exception { SqlSession openSession = getSqlSessionFactory().openSession(); try { System.out.println("++++++++++---- tp48.测试动态sql_bind"); EmployeeMapper_DynamicSQL mapper = openSession.getMapper(EmployeeMapper_DynamicSQL.class); Employee e=new Employee(); e.setLastName("e"); // e.setLastName("%e%"); 直接在这里写上模糊查询的语句,更加省时 List<Employee> list = mapper.getEmpsTestInnerParameter(e); for(Employee e1:list) System.out.println(e1); openSession.commit(); } finally { openSession.close(); } }
测试结果
++++++++++---- tp48.测试动态sql_bind DEBUG 12-05 18:11:36,236 ==> Preparing: select * from tbl_employee where last_name like ? (BaseJdbcLogger.java:145) DEBUG 12-05 18:11:36,257 ==> Parameters: _e%(String) (BaseJdbcLogger.java:145) DEBUG 12-05 18:11:36,270 <== Total: 1 (BaseJdbcLogger.java:145) Employee{id=1, lastName='Jerry2333', email='233@...', gender='1', dept=null}