0106—mybatis单独配置
来源:互联网 发布:运营数据分析专员 编辑:程序博客网 时间:2024/05/21 19:39
config.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration><!-- mybatis别名定义 --><typeAliases><typeAlias alias="Student" type="com.bean.Student" /></typeAliases><environments default="development"><environment id="development"><transactionManager type="JDBC" /><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver" /><property name="url"value="jdbc:mysql://192.168.172.131:3306/test?characterEncoding=gbk" /><property name="username" value="root" /><property name="password" value="admin" /></dataSource></environment></environments><!-- mybatis的mapper文件,每个xml配置文件对应一个接口 --><mappers><mapper resource="com/dao/student.xml" /></mappers></configuration>
studentDao.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.dao.StudentDao"><insert id="saveStudent" parameterType="Student"useGeneratedKeys="true" keyProperty="sid">insert into student (name) values(#{name})</insert><select id="findStudentBySid" parameterType="int" resultType="Student">select * from `student` where student.sid = #{sid}</select><delete id="deleteStudentBySid" parameterType="int">delete fromstudent where sid=#{sid}</delete><update id="updateStudentBySid" parameterType="Student">update student setname = #{name} where sid= #{sid}</update></mapper>
test;
static {try {reader = Resources.getResourceAsReader("Configuration.xml");sessionFac = new SqlSessionFactoryBuilder().build(reader);} catch (IOException e) {fail("Not yet implemented");}}public static void updateStudentInfo() {session = sessionFac.openSession();StudentDao dao = session.getMapper(StudentDao.class);Student sutdent = new Student();sutdent.setSid(1);sutdent.setName("王菲");int code = dao.updateStudentBySid(sutdent);System.out.println(code == 0 ? "fail !" : "success!");}
0 0
- 0106—mybatis单独配置
- mybatis单独使用
- VS2010+Opencv配置——不用每个工程单独配置
- 单独配置secondarynamenode
- tomcat 单独启动配置
- 单独使用mybatis整合mysql案例
- MVC中单独配置Log4Net
- web项目 ehcache 单独配置
- PLSQLDeveloper单独配置的参数
- PLSQLDeveloper单独配置的参数
- MyBatis初探——MyBatis配置
- mybatis学习-入门(1)-单独使用mybatis
- mybatis 配置文件configuration environments以及单独使用mybatis的demo
- mybatis 配置文件configuration environments以及单独使用mybatis的demo
- 单独
- 单独
- SSH(第一步)—— 单独配置Spring框架到web项目
- SSH(第二步)—— 单独配置Struts2框架到web项目
- routing代码分析1--ProphetRouter
- js-dom树2(删除,复制,替换节点)
- git命令
- 深入理解Java:注解(Annotation)--注解处理器
- 怎样连接SQL Server Local DB
- 0106—mybatis单独配置
- 带色彩恢复的视网膜增强算法实现 (MATLAB版本)
- 梯度下降法 matlab
- CentOS源码编译安装Haproxy
- android dalvik heap 浅析
- editText 滚动事件和长按事件冲突
- java常用的7大排序算法汇总(个人收藏)
- laravel5 路由配置 技巧
- HDU 4643 GSM