mybatis入门配置详解及实例下载
来源:互联网 发布:unity3d lua 开发游戏 编辑:程序博客网 时间:2024/05/17 22:01
1、conf.xml文件配置
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <a target=_blank href="http://mybatis.org/dtd/mybatis-3-mapper.dtd">http://mybatis.org/dtd/mybatis-3-mapper.dtd</a>><configuration><environments default="development"> <enviroment id="development"> <transactionManager type="JDBC" /><datasource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql//localhost:3306/monitor" /><property name="username" value="root" /><property name="password" value="123456" /></dataSource></enviroment></enviroments><mappers> <mapper resource="com/dcfs/zhangfyb/config/modelMapping.xml" /></mappers></configuration>
2、modelMapping文件配置详解
<pre class="html" name="code"><?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <a target=_blank href="http://mybatis.org/dtd/mybatis-3-mapper.dtd">http://mybatis.org/dtd/mybatis-3-mapper.dtd</a>><mapper namespace="com.dcfs.zhangfyb.config.modelMapping"><update id="updateModel" parameterType="com.dcfs.zhangfyb.model"> update event_type set description=#{DESCRIPTION} where name= #{NAME}</update><select id="getmodel" parameterType="string" resultType="com.dcfs.zhangfyb.model">select * from event_type where 1=1</select></mapper>
</pre><pre class="html" name="code">3、model类
public class Model{private String name; private String description; private String des;public String getDes(){ return des;} public void setDes (String des){ this.des = des;}public String getName(){ return name;}public void setName(String name){this.name = name;}public String getDescription(){ return description;}public void setDescription(String description){ this.description = description;}}
4、测试类
<pre class="html" name="code">public class Test{public static void main(String[] args){ String resource="conf.xml"; InputStream is = Test.class.getClassLoader().getResourceAsStream(resource); SqlSessionFactory sessionfactory = new SqlSessionFactoryBuilder().build(is); SqlSession session =sessionfactory.openSession();String state = "com.dcfs.zhangfyb.comfig.modelMapping.getModel"
List<Model> lists = session.selectList(state);
for(Model list:lists){
System.out.println(list.getName() + " " + lsit.getDescription());
}}}
0 0
- mybatis入门配置详解及实例下载
- Mybatis入门及配置详解
- MyBatis入门及配置
- Spring Security 3.1.3最小入门配置及实例下载
- MyBatis环境配置及入门
- MyBatis入门配置及操作
- Mybatis配置及功能详解
- MyBatis入门初级教程(1)---下载与配置
- Mybatis及与spring集成入门实例
- SpringMVC入门实例及详解
- Spring+SpringMVC+Mybatis 两种入门级基本配置及登录实例
- mybatis下载及开发环境配置
- Mybatis入门配置及基本查询
- MyBatis入门配置及简单应用
- Java入门实例classpath及package详解
- Java入门实例classpath及package详解
- Java入门实例classpath及package详解
- Java入门实例classpath及package详解
- Android模块化编程之引用本地的aar
- 200,UIDevice设备类
- 把Java的class文件转为EXE文件的八种方法
- 滑动删除ListView
- 第1章第2节练习题14 判断子序列
- mybatis入门配置详解及实例下载
- Java IO流分析整理
- hbuider 框架分析
- win32窗口全屏
- SpringMVC基础Demo搭建——annotation形式
- easy-ui使用指南
- cvc-complex-type.2.4.d: 发现了以元素 'd:skin' 开头的无效内容。此处不应含有子元素。
- java:IO流学习小结
- 正则表达式大全---进阶篇