当前位置: 首页 > news >正文

石家庄做淘宝网站地名网站建设方案

石家庄做淘宝网站,地名网站建设方案,超酷win8风格企业网站织梦模板,网页设计心得体会300🐌个人主页: 🐌 叶落闲庭 💨我的专栏:💨 c语言 数据结构 javaEE 操作系统 Redis 石可破也,而不可夺坚;丹可磨也,而不可夺赤。 MyBatisPlus 一、快速入门1.1 引入MyBatisP…

在这里插入图片描述

🐌个人主页: 🐌 叶落闲庭
💨我的专栏:💨
c语言
数据结构
javaEE
操作系统
Redis

石可破也,而不可夺坚;丹可磨也,而不可夺赤。


MyBatisPlus

  • 一、快速入门
    • 1.1 引入MyBatisPlus起步依赖
    • 1.2 自定义的Mapper继承MyBatisPlus的BaseMapper接口
    • 1.3 对比Mybatis
    • 1.4 MyBatisPlus的增删改查方法
  • 二、MyBatisPlus常用注解
    • 2.1 MyBatisPlus常用注解如下
  • 三、MyBatisPlus常用配置

一、快速入门

MyBatisPlus官方提供了starter,其中集成了Mybatis和MybatisPlus的所有功能,并且实现了自动装配效果。

1.1 引入MyBatisPlus起步依赖

<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.2</version>
</dependency>

1.2 自定义的Mapper继承MyBatisPlus的BaseMapper接口

public interface UserMapper extends BaseMapper<User> {
}

1.3 对比Mybatis

  • 要操作的数据库表结构:
create table user
(id      int not null primary key,account int null
);
  • Mybatis的UserMapper.java:
public interface UserMapper {int insert(User row);int insertSelective(User row);User selectByPrimaryKey(Integer id);int updateByPrimaryKeySelective(User row);int updateByPrimaryKey(User row);
}
  • Mybatis的UserMapper .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="com.demo.mapper.UserMapper"><resultMap id="BaseResultMap" type="com.demo.po.User"></resultMap><sql id="Base_Column_List">id, account</sql><select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">select <include refid="Base_Column_List" />from userwhere id = #{id,jdbcType=INTEGER}</select><insert id="insert" parameterType="com.demo.po.User">insert into user (id, account)values (#{id,jdbcType=INTEGER}, #{account,jdbcType=INTEGER})</insert><insert id="insertSelective" parameterType="com.demo.po.User">insert into user<trim prefix="(" suffix=")" suffixOverrides=","><if test="id != null">id,</if><if test="account != null">account,</if></trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="id != null">#{id,jdbcType=INTEGER},</if><if test="account != null">#{account,jdbcType=INTEGER},</if></trim></insert><update id="updateByPrimaryKeySelective" parameterType="com.demo.po.User">update user<set><if test="account != null">account = #{account,jdbcType=INTEGER},</if></set>where id = #{id,jdbcType=INTEGER}</update><update id="updateByPrimaryKey" parameterType="com.demo.po.User">update userset account = #{account,jdbcType=INTEGER}where id = #{id,jdbcType=INTEGER}</update>
</mapper>
  • MyBatisPlus只需UserMapper.java继承 BaseMapper<>即可:
public interface UserMapper extends BaseMapper<User> {
}

1.4 MyBatisPlus的增删改查方法

@SpringBootTest
class DemoApplicationTests {@Autowiredprivate UserMapper userMapper;@Testvoid testInsert() {User user = new User();user.setId(5);user.setAccount(2000);userMapper.insert(user);}@Testvoid testSelectById() {User user = userMapper.selectById(5);System.out.println(user);}@Testvoid testUpdateById() {User user = new User();user.setId(5);user.setAccount(8000);userMapper.updateById(user);}@Testvoid testDeleteById() {userMapper.deleteById(5);}}

二、MyBatisPlus常用注解

MyBatisPlus:通过扫描实体类,并基于反射获取实体类信息作为数据库表信息。

  • 类名驼峰转下划线作为表名
  • 名为id的字段作为主键
  • 变量名驼峰转下划线作为表的字段名

2.1 MyBatisPlus常用注解如下

  • @TableName:用来指定表名
  • @TableId:用来指定表中的主键字段信息
  • @TableFiled:用来指定表中的普通字段信息

MyBatisPlus官网:https://www.baomidou.com/pages/223848/#tablename


在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


三、MyBatisPlus常用配置

MyBatisPlus中的配置大都是默认配置好的,我们使用的时候基本不用修改大量的配置,除非遇到特殊的情况需要设置一些配置,可以参考MyBatisPlus的官方文档进行修改。

mybatis-plus:type-aliases-package: com.demo.pomapper-locations: classpath*:mapper/**/*.xml  # 默认global-config:db-config:id-type: auto # id类型自增长

在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


http://www.yayakq.cn/news/222856/

相关文章:

  • 怎么查看网站的pv uv广告设计网站排行榜前十名有哪些
  • 深圳企业品牌网站外贸出口公司网站建设方案
  • 图片演示dw做网站外贸网站推广收费
  • 淄博桓台网站建设报价贵阳百度公司建网站电话
  • 织梦修改网站主页贵阳做网站软件
  • 东莞企创做网站怎么样seo是什么的简称
  • 多个链接的网站怎么做的做公司网站的推广工作怎样
  • 做阿里网站卖东西赚钱可以做投票的网站
  • 优质的设计网站有哪些网站的服务器是什么
  • 漂亮产品网站赣州建设培训网官网
  • 哪个cms方便快速建站建设厅官方网站职称
  • 可以做任务看漫画的漫画网站网站开发的英文参考文献
  • 网站审核备案表趣php网站开发实战代码
  • 网站流量分析sharepoint网站开发
  • 广州外贸型网站建设wordpress订单管理系统
  • 北京网站建设方案飞沐抖音logo在线设计生成器免费
  • 深圳网站建设小程序中级平面设计师证书有用吗
  • 网站建设标新立异深圳南山工厂网站建设费用
  • 承德微网站建设做建材营销型网站
  • 椒江网站建设公司外流网站建设
  • 宣传旅游网站建设的观点是什么宁德做网站公司
  • 做网站内嵌地图电工学高等教育出版社久久建筑网
  • 广州网站建设公司排名wordpress 类似的
  • 龙岗南联网站建设公司南通建设中标查询网站
  • 湛江市政工程建设公司网站做视频直播网站
  • 个人博客网站制作流程365建筑人才网
  • 网站推广广告做网站的素材都在哪里下载
  • 整站优化排名连运港网络公司做网站
  • 为什么自己做的网站uc打不开网站新域名查询
  • flash网站后台大连做网站的企业