mybatis第3天
来源:互联网 发布:visio2007网络图形包 编辑:程序博客网 时间:2024/05/01 12:19
<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"/>
- mybatis第3天
- mybatis学习第3天
- mybatis第2天
- mybatis第4天
- mybatis第5天
- mybatis开始第1天
- MyBatis入门第3天--高级映射与查询缓存
- MyBatis入门第1天--MyBatis基础知识(一)
- MyBatis入门第2天--MyBatis基础知识(二)
- Spring第1天+mybatis注解:
- MyBatis第一天
- Mybatis第一天
- mybatis第一篇
- mybatis开发(第一天)
- mybatis开发(第三天)
- Mybatis学习第一天
- MyBatis入门--第一天
- MyBatis--第三天
- [提权禁区]1433端口入侵提权
- C/C++中内联函数与静态函数
- kmem_cache 初始化
- 打开80端口
- OPengl实现小球围绕大球旋转的效果
- mybatis第3天
- 《C++》 04 C++ 常量
- mysql索引总结----mysql 索引类型以及创建
- Hibernate load()和get()的区别
- php7.0.2安装
- mysql例子
- 欢迎使用CSDN-markdown编辑器
- 坚持
- 关于gradle版本问题导致的一系列奇葩问题探讨!