mybatis学习总结
SqlSession session = sqlSessionFactory.openSession(); try { // do work } finally { session.close(); }
SqlSession session = sqlSessionFactory.openSession(); try { BlogMapper mapper = session.getMapper(BlogMapper.class); // do work } finally { session.close(); } ?
?
BIT FLOAT CHAR TIMESTAMP OTHER UNDEFINED TINYINT REAL VARCHAR BINARY BLOB NVARCHAR SMALLINT DOUBLE LONGVARCHAR VARBINARY CLOB NCHAR INTEGER NUMERIC DATE LONGVARBINARY BOOLEAN NCLOB BIGINT DECIMAL TIME NULL CURSOR ?
<select id="selectTeacher" parameterType="Map" resultType="com.myapp.domain.Teacher"> select * from Teacher where c_id=#{id} and sex=#{sex} </select>
Map<String,String> map=new HasMap<String,String>(); map.put("id","2"); map.put("sex","男"); List<Teacher> tList = teacherMapper.selectTeacher(map); for (Teacher entityTemp : tList) { System.out.println(entityTemp.toString()); }??
I.当传入的map中既有基本数据类型的数据又有bean时
?
<insert id="insertStudentWithMoreParams" parameterType="map"> insert into ${t}(stuid,stuname,stuage) values (#{s.stuid}, #{s.stuname,jdbcType=VARCHAR},#{s.stuage}) </insert>
?
String t = "t_student";Student s = new Student();s.setXXX();....Map map = new HashMap();map.put("t", t);map.put("s", s);mapper.insertStudentWithMoreParams(map);?
J.$只能用于获取复杂对象如bean,map的成员值,而#既可以获取复杂对象的成员值,还可以获取简单变量的值,当只传入一个简单变量作为参数时,只能用#获取。
。。。