mybatis 学习三 关键文件解析
1: mybatis-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>
<!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 -->
<typeAliases>
<typeAlias type="com.deppon.test04.entity.StudentEntity" alias="StudentEntity"/>
</typeAliases>
<mappers>
<mapper resource="StudentMapper.xml" /> <!-- 可以定义多个mapper>
</mappers>
</configuration>
2: StudentMapper.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.deppon.test04.dao.StudentMapper">
<resultMap type="StudentEntity" id="studentResultMap">
<id property="studentID" column="STUDENT_ID"/>
<result property="studentName" column="STUDENT_NAME"/>
<result property="studentSex" column="STUDENT_SEX"/>
<result property="studentBirthday" column="STUDENT_BIRTHDAY"/>
</resultMap>
<!-- 查询学生,根据id -->
<select id="getStudent" parameterType="String" resultType="com.deppon.test04.entity.StudentEntity" resultMap="studentResultMap">
<![CDATA[
SELECT * from STUDENT_TBL ST
WHERE ST.STUDENT_ID = #{studentID}
]]>
</select>
<!-- 查询学生列表 -->
<select id="getStudentAll" resultType="com.deppon.test04.entity.StudentEntity" resultMap="studentResultMap">
<![CDATA[
SELECT * from STUDENT_TBL
]]>
</select>
</mapper>
3: mysql.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/student_manager?user=root&password=root&useUnicode=true&characterEncoding=UTF-8
4: dispatcherServlet
<mvc:annotation-driven />
<context:component-scan base-package="liming.maven.example" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 导入属性配置文件 -->
<context:property-placeholder location="classpath:mysql.properties" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="studentMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.deppon.test04.dao.StudentMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
mybatis 学习三 关键文件解析的更多相关文章
- MyBatis学习02(配置解析)
配置解析 核心配置文件 mybatis-config.xml 系统核心配置文件 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置和属性信息. 能配置的内容如下: configur ...
- MyBatis学习(三)---MyBatis和Spring整合
想要了解MyBatis基础的朋友可以通过传送门: MyBatis学习(一)---配置文件,Mapper接口和动态SQL http://www.cnblogs.com/ghq120/p/8322302. ...
- Mybatis基础学习(三)—映射文件
一.输入映射 1.parameterType 指定输入参数的Java类,可以使用别名或者类的全限定名.它也可以接受基本数据类型.POJO对象.HashMap. (1)基本数据类型 (2 ...
- MyBatis笔记03------XXXMapper.xml文件解析
SQL映射文件的配置解析 当我们写好mapper(dao)层接口时,然后在对应的XXXMapper.xml文件中写业务逻辑对应的SQL映射语句,通过这个文件中可以实现CRU操作,那么下面说明如何编写这 ...
- Mybatis学习4——核心文件sqlMapperConfig.xml属性
1.外部文件jdbc.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mybatis ...
- Mybatis学习--Mapper XML文件
学习笔记,选自Mybatis官方中文文档:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#insert_update_and_delete My ...
- MyBatis学习(三)
前言 感觉学习进度还是比较慢啊,一整天的学习效率不是很高,一会看电视,一会喝茶,对自己的要求不严格...今天就说说关联表数据的插入以及别名的使用. 正文 1.关联插入 之前,我在数据库中已经创建了一张 ...
- Android学习----AndroidManifest.xml文件解析
一个Android应用程序的结构: 一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了pack ...
- mybatis学习三
Mybatis与pageHelper分页: 分页分为假分页和真分页对应的专业术语叫做逻辑分页和物理分页 逻辑分页:将所有的数据从数据库查询出来,根据需求截取符合要求的数据返回,方便统一但效 ...
随机推荐
- 字符串处理sdut 2411
题目:http://www.sdutacm.org/sdutoj/problem.php?action=showproblem&problemid=2411 关于字符串处理的题,此题坑点很多w ...
- springmvc中url-url-pattern /和/*的区别
在使用springmvc时,都会在web.xml中配置一个dispatchservlet,如下: <listener> <listener-class> org.springf ...
- 【P2629】好消息,坏消息(前缀和+单调队列优化DP)
一激动一颓就会忘了总结... 前面的大黄题就不总结了. 这个题我只想说一声艹,一开始的思路就是正确的,然后计算的时候有了一个瑕疵,不过很快也就改过来了.然后却一直连样例都过不了.仔仔细细看了老半天,经 ...
- 基于jetty镜像的ossfs镜像docker镜像构建
阿里云ossfs:https://help.aliyun.com/document_detail/32196.html?spm=5176.product31815.6.514.yVI0xM 以上是阿里 ...
- 泛型学习第一天:List与IList的区别 (二)
原文: 探讨Ilist<>与List<> 首先要了解一点的是关于接口的基础知识: 接口不能直接实例化但是接口派生出来的抽象类可以实例化所有派生出来的抽象类都可以强制转换成接口的 ...
- div css 练习1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 关于linux的/var/www/html
linux目录下有个目录:/var/www/html,把文件放到这个目录下就可以通过IP很方便的访问, 如果要访问 /var/www/html/myfolder/test.html 我在浏览器地址栏输 ...
- IntelliJ Idea 免费激活方法免激活码
1. 到网站 http://idea.lanyus.com/ 获取注册码. 2.填入下面的license server: http://intellij.mandroid.cn/ http://ide ...
- nova Rescue 和 Unrescue
usage: nova rescue [--password <password>] [--image <image>] <server> Reboots a se ...
- sql处理数据库锁的存储过程
/*--处理死锁 查看当前进程,或死锁进程,并能自动杀掉死进程 因为是针对死的,所以如果有死锁进程,只能查看死锁进程 当然,你可以通过参数控制,不管有没有死锁,都只查看死锁进程 --邹建 2004.4 ...