创建数据库
CREATE DATABASE `mybatis`;
跳转至数据库中
USE `mybatis`;
创建表
CREATE TABLE `user`(
`id` INT(20) NOT NULL PRIMARY KEY,
`name` VARCHAR(30) DEFAULT NULL,
`pwd` VARCHAR(30) DEFAULT NULL
)ENGINE=INNODB DEFAULT CHARSET=utf8;
增:
insert into mybatis.user(id,name,pwd) values (#{id},#{name},#{pwd})
删:
delete from mybatis.user where id=#{id}
改:
update mybatis.user set name=#{name},pwd=#{pwd} where id=#{id}
查:
select * from "mybatis.user1(数据库名.表名)" where id=#{id}(#{}用于获取参数)
模糊查询:
1.在调用查询语句时传递通配符:
List<User> userList = mapper.getUserLike("%李%");
2.在sql语句中拼接通配符
select * from mybatis.user where name like "%"#{value}"%"