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分页: 分页分为假分页和真分页对应的专业术语叫做逻辑分页和物理分页 逻辑分页:将所有的数据从数据库查询出来,根据需求截取符合要求的数据返回,方便统一但效 ...
随机推荐
- IntelliJ Idea 快捷键精选
Alt+Enter,导入包,自动修正Ctrl+F,查找文本Alt+Up/Down,上/下移一行:在方法间快速移动定位:与光标位置有关Alt+Shift+Up,多次up可选中一行Ctrl+X,剪切行Ct ...
- Linux查看文件编码格式及文件编码转换<转>
如果你需要在Linux 中操作windows下的文件 ,那么你可能会经常遇到文件 编码 转换的问题.Windows中默认的文件 格式是GBK(gb2312),而Linux 一般都是UTF-8.下面介绍 ...
- 关于发邮件报错535 Error:authentication failed&553 authentication is required
553 authentication is required:这个错误的意思是你必须需要认证. 也就是说,你连接smtp服务器的时候必须使用密码来连接:下面代码红色那句 代码: @Override p ...
- processing学习整理---Input(输入)
1.鼠标1D. 左右移动鼠标可移动天平. “mouseX”变量用于控制矩形的大小和颜色. void setup(){ size(640,360); noStroke(); colorMode(RGB, ...
- java基础9(IO流)-File类
File类 File:文件和目录路径名的抽象表示形式.即java中把文件或者目录都封装成File对象 代码练习1 import java.io.File; public class FileDemo1 ...
- HDFS的设计
当数据集的大小超过一台独立的物理计算机的存储能力时,就有必要对它进行分区(partition)并存储到若干台单独的计算机上.管理网络中跨多台计算机存储的文件系统成为分布式文件系统(distribute ...
- JavaScript -- 练习 window 流氓广告
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 解决Android7.1.1中无法打开/data目录的问题
声明:本技巧借鉴https://segmentfault.com/a/1190000008416511这个大神的文章 一.复制android Sdk安装目录的platform-tools路径: 二.w ...
- AOP理解,待细看
http://jinnianshilongnian.iteye.com/blog/1474325
- odl v2 driver
networking-odl项目的目的/用途就是sync odl和neutron的资源数据库和状态 v1中对于每个neutron的资源操作都相应的调用odl restfu api来同步odl,但问题有 ...