MyBatis框架(增删改)
来源:互联网 发布:sql developer导入dmp 编辑:程序博客网 时间:2024/05/17 03:08
步骤1:在pom.xml中添加一个log4j依赖
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
步骤2:在Resource目录中添加一个名称为log4j.property文件
util:工具类层
public class MyBatisUtil {
//Mybatis
static String path="Mybatis-config.xml";
static SqlSessionFactory factory;
static{
try {
InputStream is = Resources.getResourceAsStream(path);
factory= new SqlSessionFactoryBuilder().build(is);
} catch (IOException e) {
e.printStackTrace();
}
}
public static SqlSession getSession(){
return factory.openSession();
}
}
底层数据表中的列和实体类中的属性,只要有一个不匹配,MyBatis框架就不能自动的帮我们装配对象了。装配出来的是null
-------SQL片段:主要解决多个列重复书写的问题
<sql id="columns">
stuid,stuname
</sql>
select <include refid="columns"></include>
---------多条件查询----------------------------------
select * from studentinfo where stuname like '%' #{stuName} '%' and stuAge>#{stuAge}
-------》
select * from studentinfo where stuname like '%' ? '%' and stuAge>?
select * from studentinfo where stuname like concat('%',#{stuName},'%') and stuAge>#{stuAge}
------>
select * from studentinfo where stuname like concat('%',?,'%') and stuAge>?
select * from studentinfo where stuname like '%${stuName}%' and stuAge>#{stuAge}
------》
select * from studentinfo where stuname like '%星星%' and stuAge>?
StudentInfoDao接口:
public interface StudentINfoDao { public List<StudentINfo> shut(); //查询所有 public StudentINfo stud(int id);//根据id查询 public int add(StudentINfo stu); //增加操作 public int update(StudentINfo stu); //修改操作 public int delete(int stuid); //删除操作 public List<StudentINfo> selectlink(StudentINfo info); //模糊查询}
小配置:
大配置:
测试:
- MyBatis框架(增删改)
- MyBatis框架学习之增删改查
- MyBatis框架增删改查(Oracle数据库)
- MyBatis框架实现简单增删改查
- 19、SSM框架-Mybatis入门概述及第一个Mybatis实例实现增删改查(1)
- Mybatis入门(三):增删改查
- mybatis的增删查改(CRUD)
- (2)MyBatis之增删改查
- mybatis增删改应用(三)
- mybatis学习(三)--增删改查
- MyBatis增删改查(CRUD)操作
- 2、Mybatis增删改查(CURD)
- mybatis入门(三)增删改查
- Mybatis 增删改查
- mybatis增删改查
- mybatis增删改查
- mybatis增删改操作
- MyBatis批量增删改
- Deep Convolutional Network Cascade for Facial Point Detection阅读笔记
- pytorch训练imagenet分类
- Java后端WebSocket的Tomcat实现
- Java异常分类
- 自动化运维之Puppet
- MyBatis框架(增删改)
- 获取iOS设备的唯一标识
- EXTRACT() 提取函数
- SHU 422 风力观测 (线段树,区间更新,区间询问历史最大值)
- UVa 1593 Alignment of code 解题报告
- ReactNative系列之十八codepush热更新
- websorm环境下,react+webpack搭建项目环境
- iOS身份证号码识别
- CSDN转载博客