- 浏览: 3992 次
- 性别:
文章分类
最新评论
jdbc.properties
db.username=root
db.password=root
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/mybatis?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8
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>
<!--引入外部资源文件 -->
<properties resource="jdbc.properties"></properties>
<!-- 给类实体取别名 -->
<typeAliases>
<!-- many2many -->
<typeAlias type="cn.itcast.mybatisrelation.many2many.Student" alias="Student"/>
<typeAlias type="cn.itcast.mybatisrelation.many2many.Course" alias="Course"/>
<!-- one2many -->
<typeAlias type="cn.itcast.mybatisrelation.one2many.Dept" alias="Dept"/>
<typeAlias type="cn.itcast.mybatisrelation.one2many.Emp" alias="Emp"/>
<!-- one2one -->
<typeAlias type="cn.itcast.mybatisrelation.one2one.Person" alias="Person"/>
<typeAlias type="cn.itcast.mybatisrelation.one2one.Passport" alias="Passport"/>
<!-- interceptor -->
<typeAlias type="cn.itcast.mybatisrelation.Interceptor.User" alias="User"/>
</typeAliases>
<plugins>
<plugin interceptor="cn.itcast.mybatisrelation.Interceptor.MyInterceptor">
<property name="prop1" value="jack"/>
<property name="prop2" value="张三"/>
</plugin>
</plugins>
<!-- 配置环境 -->
<environments default="default">
<environment id="default">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${db.driverClassName}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="url" value="${db.url}"/>
</dataSource>
</environment>
</environments>
<!-- 实体映射文件的注册 -->
<mappers>
<mapper resource="cn/itcast/mybatisrelation/many2many/Student.xml"/>
<mapper resource="cn/itcast/mybatisrelation/many2many/Course.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2many/Dept.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2many/Emp.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2one/Person.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2one/Passport.xml"/>
<mapper resource="cn/itcast/mybatisrelation/Interceptor/User.xml"/>
</mappers>
</configuration>
MybatisUtil.java
package cn.itcast.mybatisresultmap.util;
import java.io.IOException;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class MybatisUtil {
private static SqlSessionFactory factory=null;
static{
try {
factory=new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static SqlSession getSqlSession(){
return factory.openSession();
}
}
User.java
package cn.itcast.mybatisresultmap.crud;
import java.io.Serializable;
public class User implements Serializable {
private Integer id;
private String username;
private String password;
set get方法....
}
User.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="cn.itcast.mybatisresultmap.crud.User">
<!-- 自定义结果集映射方式 -->
<resultMap type="User" id="userMapper">
<id property="id" column="user_id"/>
<result property="username" column="user_name"/>
<result property="password" column="user_password"/>
</resultMap>
<!-- 添加 -->
<insert id="save" parameterType="User" useGeneratedKeys="true" keyProperty="id">
insert into t_user values(null,#{username},#{password})
</insert>
<!-- 查询所有 -->
<select id="list" resultMap="userMapper">
select * from t_user order by user_id
</select>
<!-- 修改 -->
<update id="update" parameterType="User">
update t_user set user_name=#{username},user_password=#{password} where user_id=#{id}
</update>
<!-- 根据id查询单条的记录 -->
<select id="get" parameterType="int" resultMap="userMapper">
select * from t_user where user_id=#{id}
</select>
<!-- 删除 -->
<delete id="delete" parameterType="int">
delete from t_user where user_id=#{id}
</delete>
</mapper>
test crud
import cn.itcast.mybatisresultmap.util.MybatisUtil;
public class MybatisCrudTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test // 查询所有
public void testList() {
SqlSession sqlSession=MybatisUtil.getSqlSession();
List<User> userList=sqlSession.selectList(User.class.getName()+".list");
for(User user:userList){
System.out.println("User对象是:"+user);
}
sqlSession.commit();
sqlSession.close();
}
@Test // 添加记录
public void testSave(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
User user=new User("小花","3333");
sqlSession.insert(User.class.getName()+".save", user);
sqlSession.commit();
sqlSession.close();
}
// 删除记录
@Test public void testDelete(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
sqlSession.delete(User.class.getName()+".delete", 10);
sqlSession.commit();
sqlSession.close();
}
// 根据id查询单条记录
@Test public void testGet(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
User user=sqlSession.selectOne(User.class.getName()+".get",2);
System.out.println("当前User对象是:"+user);
sqlSession.commit();
sqlSession.close();
}
// 修改记录
@Test public void testUpdate(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
User user=new User(5,"小五","5555");
sqlSession.update(User.class.getName()+".update", user);
sqlSession.commit();
sqlSession.close();
}
}
manytomany
public class Student implements Serializable {
private Integer id;
private String name;
private String sex;
private Date birthday;
private String hobby;
private List<Course> courseList=new ArrayList<Course>();
set get方法....
}
public class Course implements Serializable {
private Integer id;
private String code;
private String name;
private List<Student> studentList=new ArrayList<Student>();
set get方法.....
}
Student.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="cn.itcast.mybatisresultmap.many2many.Student">
<!-- 自定义resultMapper -->
<resultMap type="Student" id="studentMapper">
<id property="id" column="student_id"/>
<result property="name" column="student_name"/>
<result property="sex" column="student_sex"/>
<result property="birthday" column="student_birthday"/>
<result property="hobby" column="student_hobby"/>
<collection property="courseList" ofType="Course">
<id property="id" column="course_id"/>
<result property="code" column="course_code"/>
<result property="name" column="course_name"/>
</collection>
</resultMap>
<!-- 添加数据 -->
<insert id="save" parameterType="Student" useGeneratedKeys="true" keyProperty="id">
insert into t_student values(null,#{name},#{sex},#{birthday},#{hobby})
</insert>
<select id="get" parameterType="int" resultMap="studentMapper">
select s.*,c.* from t_student s left join t_student_course sc on s.student_id=sc.sid left join t_course c
on c.course_id=sc.cid where s.student_id=#{id}
</select>
</mapper>
Course.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="cn.itcast.mybatisresultmap.many2many.Course">
<!-- 自定义resultMap -->
<resultMap type="Course" id="courseMapper">
<id property="id" column="course_id"/>
<result property="code" column="course_code"/>
<result property="name" column="course_name"/>
<collection property="studentList" ofType="Student">
<id property="id" column="student_id"/>
<result property="name" column="student_name"/>
<result property="sex" column="student_sex"/>
<result property="birthday" column="student_birthday"/>
<result property="hobby" column="student_hobby"/>
</collection>
</resultMap>
<!-- 录入数据 -->
<insert id="save" parameterType="Course" useGeneratedKeys="true" keyProperty="id">
insert into t_course values(null,#{code},#{name})
</insert>
<!-- 录入中间表 -->
<insert id="saveMidTable" parameterType="hashmap" useGeneratedKeys="true" keyProperty="id">
insert into t_student_course values(null,#{sid},#{cid})
</insert>
<select id="get" parameterType="int" resultMap="courseMapper">
select c.*,s.* from t_course c left join t_student_course sc on c.course_id=sc.cid left join t_student s
on sc.sid=s.student_id where c.course_id=#{id}
</select>
</mapper>
public class Many2ManyTest {
private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testSave()throws Exception{
Course c1=new Course();
c1.setCode("c001");
c1.setName("js");
Course c2=new Course();
c2.setCode("c002");
c2.setName("freemarker");
Student s1=new Student();
s1.setName("小四");
s1.setSex("男");
s1.setBirthday(sdf.parse("1992-09-13"));
s1.setHobby("看书");
Student s2=new Student();
s2.setName("小小");
s2.setSex("女");
s2.setBirthday(sdf.parse("1992-08-13"));
s2.setHobby("逛街");
// 添加关系
s1.getCourseList().add(c1);
s1.getCourseList().add(c2);
s2.getCourseList().add(c1);
s2.getCourseList().add(c2);
SqlSession sqlSession=MybatisUtil.getSqlSession();
sqlSession.insert(Student.class.getName()+".save", s1);
sqlSession.insert(Student.class.getName()+".save", s2);
sqlSession.insert(Course.class.getName()+".save", c1);
sqlSession.insert(Course.class.getName()+".save", c2);
Map<String,Object> map=new HashMap<String,Object>();
// 中间表的处理
for(Course cc:s1.getCourseList()){
map.put("sid",s1.getId());
map.put("cid", cc.getId());
sqlSession.insert(Course.class.getName()+".saveMidTable", map);
}
for(Course cc:s2.getCourseList()){
map.put("sid",s2.getId());
map.put("cid", cc.getId());
sqlSession.insert(Course.class.getName()+".saveMidTable", map);
}
sqlSession.commit();
sqlSession.close();
}
/**
* 根据学生的主键id查询某个学生 并且查出这个学生的所有课程
*/
@Test public void testGetStudentById(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
Student stu=sqlSession.selectOne(Student.class.getName()+".get", 1);
System.out.println("stu是:"+stu);
for(Course cc:stu.getCourseList()){
System.out.println("cc是:"+cc);
}
sqlSession.commit();
sqlSession.close();
}
/**
* 根据课程的主键id查询某门课程 并且查出学这门课程的学生们
*/
@Test public void testGetCourseById(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
Course cc=sqlSession.selectOne(Course.class.getName()+".get",;
System.out.println("cc是:"+cc);
for(Student ss:cc.getStudentList()){
System.out.println("ss是:"+ss);
}
sqlSession.commit();
sqlSession.close();
}
}
db.username=root
db.password=root
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/mybatis?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8
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>
<!--引入外部资源文件 -->
<properties resource="jdbc.properties"></properties>
<!-- 给类实体取别名 -->
<typeAliases>
<!-- many2many -->
<typeAlias type="cn.itcast.mybatisrelation.many2many.Student" alias="Student"/>
<typeAlias type="cn.itcast.mybatisrelation.many2many.Course" alias="Course"/>
<!-- one2many -->
<typeAlias type="cn.itcast.mybatisrelation.one2many.Dept" alias="Dept"/>
<typeAlias type="cn.itcast.mybatisrelation.one2many.Emp" alias="Emp"/>
<!-- one2one -->
<typeAlias type="cn.itcast.mybatisrelation.one2one.Person" alias="Person"/>
<typeAlias type="cn.itcast.mybatisrelation.one2one.Passport" alias="Passport"/>
<!-- interceptor -->
<typeAlias type="cn.itcast.mybatisrelation.Interceptor.User" alias="User"/>
</typeAliases>
<plugins>
<plugin interceptor="cn.itcast.mybatisrelation.Interceptor.MyInterceptor">
<property name="prop1" value="jack"/>
<property name="prop2" value="张三"/>
</plugin>
</plugins>
<!-- 配置环境 -->
<environments default="default">
<environment id="default">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="${db.driverClassName}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="url" value="${db.url}"/>
</dataSource>
</environment>
</environments>
<!-- 实体映射文件的注册 -->
<mappers>
<mapper resource="cn/itcast/mybatisrelation/many2many/Student.xml"/>
<mapper resource="cn/itcast/mybatisrelation/many2many/Course.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2many/Dept.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2many/Emp.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2one/Person.xml"/>
<mapper resource="cn/itcast/mybatisrelation/one2one/Passport.xml"/>
<mapper resource="cn/itcast/mybatisrelation/Interceptor/User.xml"/>
</mappers>
</configuration>
MybatisUtil.java
package cn.itcast.mybatisresultmap.util;
import java.io.IOException;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class MybatisUtil {
private static SqlSessionFactory factory=null;
static{
try {
factory=new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static SqlSession getSqlSession(){
return factory.openSession();
}
}
User.java
package cn.itcast.mybatisresultmap.crud;
import java.io.Serializable;
public class User implements Serializable {
private Integer id;
private String username;
private String password;
set get方法....
}
User.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="cn.itcast.mybatisresultmap.crud.User">
<!-- 自定义结果集映射方式 -->
<resultMap type="User" id="userMapper">
<id property="id" column="user_id"/>
<result property="username" column="user_name"/>
<result property="password" column="user_password"/>
</resultMap>
<!-- 添加 -->
<insert id="save" parameterType="User" useGeneratedKeys="true" keyProperty="id">
insert into t_user values(null,#{username},#{password})
</insert>
<!-- 查询所有 -->
<select id="list" resultMap="userMapper">
select * from t_user order by user_id
</select>
<!-- 修改 -->
<update id="update" parameterType="User">
update t_user set user_name=#{username},user_password=#{password} where user_id=#{id}
</update>
<!-- 根据id查询单条的记录 -->
<select id="get" parameterType="int" resultMap="userMapper">
select * from t_user where user_id=#{id}
</select>
<!-- 删除 -->
<delete id="delete" parameterType="int">
delete from t_user where user_id=#{id}
</delete>
</mapper>
test crud
import cn.itcast.mybatisresultmap.util.MybatisUtil;
public class MybatisCrudTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test // 查询所有
public void testList() {
SqlSession sqlSession=MybatisUtil.getSqlSession();
List<User> userList=sqlSession.selectList(User.class.getName()+".list");
for(User user:userList){
System.out.println("User对象是:"+user);
}
sqlSession.commit();
sqlSession.close();
}
@Test // 添加记录
public void testSave(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
User user=new User("小花","3333");
sqlSession.insert(User.class.getName()+".save", user);
sqlSession.commit();
sqlSession.close();
}
// 删除记录
@Test public void testDelete(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
sqlSession.delete(User.class.getName()+".delete", 10);
sqlSession.commit();
sqlSession.close();
}
// 根据id查询单条记录
@Test public void testGet(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
User user=sqlSession.selectOne(User.class.getName()+".get",2);
System.out.println("当前User对象是:"+user);
sqlSession.commit();
sqlSession.close();
}
// 修改记录
@Test public void testUpdate(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
User user=new User(5,"小五","5555");
sqlSession.update(User.class.getName()+".update", user);
sqlSession.commit();
sqlSession.close();
}
}
manytomany
public class Student implements Serializable {
private Integer id;
private String name;
private String sex;
private Date birthday;
private String hobby;
private List<Course> courseList=new ArrayList<Course>();
set get方法....
}
public class Course implements Serializable {
private Integer id;
private String code;
private String name;
private List<Student> studentList=new ArrayList<Student>();
set get方法.....
}
Student.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="cn.itcast.mybatisresultmap.many2many.Student">
<!-- 自定义resultMapper -->
<resultMap type="Student" id="studentMapper">
<id property="id" column="student_id"/>
<result property="name" column="student_name"/>
<result property="sex" column="student_sex"/>
<result property="birthday" column="student_birthday"/>
<result property="hobby" column="student_hobby"/>
<collection property="courseList" ofType="Course">
<id property="id" column="course_id"/>
<result property="code" column="course_code"/>
<result property="name" column="course_name"/>
</collection>
</resultMap>
<!-- 添加数据 -->
<insert id="save" parameterType="Student" useGeneratedKeys="true" keyProperty="id">
insert into t_student values(null,#{name},#{sex},#{birthday},#{hobby})
</insert>
<select id="get" parameterType="int" resultMap="studentMapper">
select s.*,c.* from t_student s left join t_student_course sc on s.student_id=sc.sid left join t_course c
on c.course_id=sc.cid where s.student_id=#{id}
</select>
</mapper>
Course.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="cn.itcast.mybatisresultmap.many2many.Course">
<!-- 自定义resultMap -->
<resultMap type="Course" id="courseMapper">
<id property="id" column="course_id"/>
<result property="code" column="course_code"/>
<result property="name" column="course_name"/>
<collection property="studentList" ofType="Student">
<id property="id" column="student_id"/>
<result property="name" column="student_name"/>
<result property="sex" column="student_sex"/>
<result property="birthday" column="student_birthday"/>
<result property="hobby" column="student_hobby"/>
</collection>
</resultMap>
<!-- 录入数据 -->
<insert id="save" parameterType="Course" useGeneratedKeys="true" keyProperty="id">
insert into t_course values(null,#{code},#{name})
</insert>
<!-- 录入中间表 -->
<insert id="saveMidTable" parameterType="hashmap" useGeneratedKeys="true" keyProperty="id">
insert into t_student_course values(null,#{sid},#{cid})
</insert>
<select id="get" parameterType="int" resultMap="courseMapper">
select c.*,s.* from t_course c left join t_student_course sc on c.course_id=sc.cid left join t_student s
on sc.sid=s.student_id where c.course_id=#{id}
</select>
</mapper>
public class Many2ManyTest {
private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void testSave()throws Exception{
Course c1=new Course();
c1.setCode("c001");
c1.setName("js");
Course c2=new Course();
c2.setCode("c002");
c2.setName("freemarker");
Student s1=new Student();
s1.setName("小四");
s1.setSex("男");
s1.setBirthday(sdf.parse("1992-09-13"));
s1.setHobby("看书");
Student s2=new Student();
s2.setName("小小");
s2.setSex("女");
s2.setBirthday(sdf.parse("1992-08-13"));
s2.setHobby("逛街");
// 添加关系
s1.getCourseList().add(c1);
s1.getCourseList().add(c2);
s2.getCourseList().add(c1);
s2.getCourseList().add(c2);
SqlSession sqlSession=MybatisUtil.getSqlSession();
sqlSession.insert(Student.class.getName()+".save", s1);
sqlSession.insert(Student.class.getName()+".save", s2);
sqlSession.insert(Course.class.getName()+".save", c1);
sqlSession.insert(Course.class.getName()+".save", c2);
Map<String,Object> map=new HashMap<String,Object>();
// 中间表的处理
for(Course cc:s1.getCourseList()){
map.put("sid",s1.getId());
map.put("cid", cc.getId());
sqlSession.insert(Course.class.getName()+".saveMidTable", map);
}
for(Course cc:s2.getCourseList()){
map.put("sid",s2.getId());
map.put("cid", cc.getId());
sqlSession.insert(Course.class.getName()+".saveMidTable", map);
}
sqlSession.commit();
sqlSession.close();
}
/**
* 根据学生的主键id查询某个学生 并且查出这个学生的所有课程
*/
@Test public void testGetStudentById(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
Student stu=sqlSession.selectOne(Student.class.getName()+".get", 1);
System.out.println("stu是:"+stu);
for(Course cc:stu.getCourseList()){
System.out.println("cc是:"+cc);
}
sqlSession.commit();
sqlSession.close();
}
/**
* 根据课程的主键id查询某门课程 并且查出学这门课程的学生们
*/
@Test public void testGetCourseById(){
SqlSession sqlSession=MybatisUtil.getSqlSession();
Course cc=sqlSession.selectOne(Course.class.getName()+".get",;
System.out.println("cc是:"+cc);
for(Student ss:cc.getStudentList()){
System.out.println("ss是:"+ss);
}
sqlSession.commit();
sqlSession.close();
}
}
相关推荐
这篇“MyBatis入门到精通”的学习资料是针对初学者设计的,旨在帮助新手快速掌握MyBatis的基本用法和高级特性。 1. **MyBatis简介** MyBatis是由Clinton Begin创建的开源项目,它是一个基于Java的持久层框架,消除...
Mybatis入门
mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例mybatis入门案例...
MyBatis入门 MyBatis是一个优秀的持久层框架,使用XML将SQL与程序解耦,便于维护。MyBatis学习简单,执行高效,是JDBC的延伸。MyBatis提供了数据库增删改查的便捷操作,极大提高了开发效率、统一的编码规则、利于...
【标题】"mybatis入门程序"是一个针对初学者的教程,旨在引导他们进入SSM(Spring、SpringMVC和MyBatis)框架的学习。MyBatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射,极大地简化了Java开发...
【MyBatis 入门教程】 MyBatis 是一个优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使你更好地将注意力集中在你的...
### MyBatis 入门知识点概述 #### 一、MyBatis 概念与特点 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis...
综上所述,"mybatis入门实例" 包含了 MyBatis 的核心概念和基本使用方法,通过对单表的 CRUD 操作,帮助初学者快速理解和掌握 MyBatis 的工作原理和实践技巧。在这个实例中,你可以看到从配置到实际操作的全过程,...
这个入门例子是针对初次接触 MyBatis 的学习者设计的,旨在通过简单的步骤和清晰的配置,帮助他们快速理解 MyBatis 的基本工作原理和核心特性。数据库环境选择了 Oracle,Oracle 是一款功能强大且广泛使用的商业级...
在这个"Mybatis入门JavaSE案例"中,我们将深入理解Mybatis的基本配置、DAO层的注解方式以及XML配置方式。 首先,让我们来了解Mybatis的配置过程。Mybatis的配置文件(mybatis-config.xml)是整个框架的入口,它包含...
这个"MyBatis入门程序"是为初学者设计的,旨在帮助他们快速理解并开始使用MyBatis。在这个程序中,我们将探讨几个关键知识点,包括MyBatis的基本架构、配置、映射文件以及如何连接MySQL数据库。 1. **MyBatis基本...
【标题】"第一个mybatis程序 mybatis入门" 涉及到的是MyBatis框架的基础使用,这是一个轻量级的Java持久层框架,它简化了与数据库交互的过程,提供了强大的映射功能。以下是对MyBatis入门的详细解析: 1. **MyBatis...
本入门程序旨在帮助初学者掌握Mybatis的基本使用,包括如何进行数据库的增删改查操作。下面我们将深入探讨这个主题。 首先,我们来了解Mybatis的核心概念: 1. **SqlSessionFactory**: 这是Mybatis的主要入口点,...
【标题】"mybatis入门项目代码"涉及到的是MyBatis框架的基础使用教程,这是一个轻量级的持久层框架,用于简化Java开发中的数据库操作。MyBatis允许开发者编写SQL语句,将数据库查询与应用程序逻辑紧密地结合起来,...
在本入门示例项目中,我们将深入理解MyBatis的基本使用方法,包括数据库交互、映射文件配置、配置文件加载、Junit测试以及日志记录。 1. 数据库SQL语句:MyBatis的核心功能之一就是将Java对象与数据库中的SQL语句...
在"mybatis入门实战之一"中,我们将深入探讨MyBatis的基础知识,包括它的安装配置、基本用法以及如何进行简单的增删改查操作。这个实战教程特别适合初学者,因为它涵盖了开发过程中常用的工具如log日志记录和Maven...
4. Mybatis的基础知识:Mybatis入门需要掌握一些基础的知识,包括配置文件的编写、Java接口的定义、SQL语句的编写等。其中,配置文件主要包括数据库连接信息、SQL语句等。 5. Mybatis与Hibernate的比较:Hibernate...
MyBatis是一款强大的Java持久层框架,它实现了SQL与Java代码的解耦,极大地提高了开发效率。本资源包是专为初学者至进阶者设计的一套完整的MyBatis学习资料,旨在帮助开发者全面理解并掌握MyBatis的核心概念和技术。...
### Mybatis框架入门知识点详解 #### 一、框架与Mybatis概述 1. **框架定义**: - **广义定义**:框架是一种系统性的、可重用的设计方案,表现为一组抽象组件及其交互方法。 - **狭义定义**:框架是可由应用...
本资源集合是针对MyBatis入门学习者设计的,涵盖了MyBatis的基本概念、核心功能以及实际应用。 首先,我们需要了解MyBatis的基本概念。MyBatis是一个基于Java的持久层框架,它提供了灵活的SQL映射机制,将SQL语句与...