wordpress 懒人图库,新乡seo优化,注册了微信小程序怎么登录,西部数码网站管理助手 没有d盘目录
前言
1.准备工作
1.1⽂件配置
1.2添加 mapper 接⼝
2.增删改查操作
2.1增(Insert) 2.2删(Delete)
2.3改(Update)
2.4查(Select) 前言 接下来我们会使用的数据表如下#xff1a; 对应的实体类为#xff1a;UserInfo
所有的准备工作都在如下文章。
MyBatis 操作…
目录
前言
1.准备工作
1.1⽂件配置
1.2添加 mapper 接⼝
2.增删改查操作
2.1增(Insert) 2.2删(Delete)
2.3改(Update)
2.4查(Select) 前言 接下来我们会使用的数据表如下 对应的实体类为UserInfo
所有的准备工作都在如下文章。
MyBatis 操作数据库入门-CSDN博客文章浏览阅读568次点赞11次收藏24次。什么是MyBatis?MyBatis是⼀款优秀的 持久层 框架⽤于简化JDBC的开发Mybatis操作数据库的入门步骤1.创建springboot⼯程2.数据库表准备、实体类3.引⼊Mybatis的相关依赖配置Mybatis(数据库连接信息)4.编写SQL语句(注解/XML) 进行测试了解更多MyBatis中文网1.创建springboot⼯程创建springboot⼯程并导⼊ mybatis的起步依赖、mysql的驱动包。https://blog.csdn.net/WHabc2002/article/details/142743762 1.准备工作
1.1⽂件配置
如果是application.yml⽂件, 配置内容如下:
mybatis:mapper-locations: classpath:mybatis/**Mapper.xml 如果是application.properties⽂件, 配置内容如下
mybatis.mapper-locationsclasspath:mapper/**Mapper.xml 按照mybatis.mapper-locations设置文件 起名无所谓最后以Mapper.xml结尾就行
1.2添加 mapper 接⼝ 数据持久层的接⼝定义接口名自已决定
import com.wh.myBatis.model.UserInfo;
import org.apache.ibatis.annotations.Mapper;import java.util.List;Mapper
public interface UserInfoXmlMapper {ListUserInfo selectAllUser();
}1.3添加MyBatis 的固定 xml 格式
在mybatis.mapper-locations的路径下 加MyBatis 的固定 xml 格式
以我为例
?xml version1.0 encodingUTF-8?
!DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd
mapper namespacecom.wh.myBatis.mapper.UserInfoXmlMapper/mapper
路径一定要正确 2.增删改查操作
为了增加开发效率我们可以使用插件。 2.1增(Insert)
UserInfoXmlMapper接口Integer insert(UserInfo userInfo);
UserInfoXmlMapper.xml的实现
?xml version1.0 encodingUTF-8?
!DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd
mapper namespacecom.wh.myBatis.mapper.UserInfoXmlMapperinsert idinsertinsert into userinfo (username, password, age, gender)values (#{username},#{password},#{age},#{gender})/insert
/mapper 如果使⽤Param设置参数名称的话, 使⽤⽅法和注解类似 返回⾃增 id 接⼝定义不变, UserInfoXmlMapper.xml 实现 设置useGeneratedKeys 和keyProperty属性 insert idinsert2 useGeneratedKeystrue keyPropertyidinsert into userinfo (username, password, age, gender)values (#{username},#{password},#{age},#{gender})/insert 2.2删(Delete)
UserInfoXmlMapper接口
Integer delete(Integer id); UserInfoXmlMapper.xml的实现
delete iddeletedelete from userinfo where id #{id}/delete
2.3改(Update)
UserInfoXmlMapper接口
Integer update(UserInfo userInfo); UserInfoXmlMapper.xml的实现 update idupdateupdate userinfo set username#{username} where id#{id}/update
2.4查(Select)
UserInfoXmlMapper接口
ListUserInfo selectAllUser();
UserInfoXmlMapper.xml的实现 select idselectAllUser resultTypecom.wh.myBatis.model.UserInfoselect * from userinfo/select MyBatis 会获取结果中返回的列名并在 Java 类中查找相同名字的属性 小驼峰与蛇形的结果映射 UserInfoXmlMapper.xml的实现 resultMap idBaseMap typecom.wh.myBatis.model.UserInfoid columnid propertyid/idresult columndelete_flag propertydeleteFlag/resultresult columncreate_time propertycreateTime/resultresult columnupdate_time propertyupdateTime/result/resultMapselect idselectAllUser2 resultMapBaseMapselect * from userinfo/select 以上为我个人的小分享如有问题欢迎讨论
都看到这了不如关注一下给个免费的赞