<deleteid="delMore">
delete from t_user where u_id in(
<foreach collection="ids"item="id" separator=",">
#{id}
</foreach>
)
</delete>
<selectid="dynaFindUser" resultMap="user">
select * from t_user where 1=1
<iftest="id != 0">
and u_id > #{id}
</if>
<if test="userName != null and userName != ''">
and u_userName like '%${userName}%'
</if>
</select>
<![CDATA[
select count(*) from tm_user
]]>
<trim prefix="where" prefixOverrides="and|or"> <!--插入where语句 ,自动判断进行条件拼接-->
<include refid="whereColumns"/> <!--引入where语句-->
</trim>
</select>
一方:
publicclass UserObj {
privateint id;
privateString name;
private int age;
private List<ResultObj> resultList = newArrayList();
}
publicclass ResultObj {
privateint id;
privateint point;
private UserObj user;
<typeAlias alias="users"type="com.map.UserObj"/>
<typeAlias alias="results"type="com.map.ResultObj"/>
<select id="findById" resultMap="user_Result">
select * from t_user where t_id=#{id}
</select>
publicclass TeacherBean {
private int id;
private String teacherName;
private List studentList;
}
publicclass StudentBean {
private int id;
private String studentName;
private List teacherList;
}
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.gjt.mm.mysql.Driver" /> 驱动
<property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&allowMultiQueries=true"></property>URL
<property name="username" value="root" />用户名
<property name="password" value="lovo" />密码
最大连接数
<property name="maxActive" value="50"></property>
最小连接数
<property name="maxIdle" value="20"></property>
<property name="maxWait" value="1000"></property>等待时间
</bean>
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property><!--数据源-->
<!--mybatis配置文件路径-->
<property name="configLocation" value="classpath:mybatis.cfg.xml"></property>
<!--自动扫描指定路径下配置文件-->
<property name="mapperLocations">
<list>
<value>classpath:orm/*.xml</value>
</list>
</property>
</bean>
<bean id="trans" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
配置使用注解完成事务
<tx:annotation-driven transaction-manager="trans"/>