在SpringBoot中先配置MyBatis 依赖
mybatis:
mapper-locations: classpath:mapper/*.xml #扫描所有mybatis的xml文件
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #日志
-- 条件查询
select * from user where id = #{id}
-- 增加数据 此处数据库id字段自增
intser into user(username , password) values (#{username} , #{password})
-- 修改
update user set username = #{username} , password = #{password} where id = #{id}
-- 删除
delete from user wher id = #{id}
-- 分页查询 下标从0开始 查询出来两个数据
-- 网页中分页
-- 第一个参数:(pageNum - 1) * pageSize
-- 第二个参数:pageSize
select * from user limit 0,2
-- 分页模糊查询
select * from user where username like concat('%', #{username}, '%') limit #{pageNum} , #{pageSize}
-- 多条件的模糊查询
select * from user where username like #{username} or email like #{email} or address like #{address}