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

长沙做一个网站多少钱优化大师安卓版

长沙做一个网站多少钱,优化大师安卓版,用wordpress做微网站,童装网站建设目标这里写目录标题 简介快速上手数据库建立创建实体类修改参数引入依赖测试常见注解介绍TableNameTableIdTableField 常见配置仓库地址 简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,…

这里写目录标题

  • 简介
  • 快速上手
    • 数据库建立
    • 创建实体类
    • 修改参数
    • 引入依赖
    • 测试
    • 常见注解介绍
      • @TableName
      • @TableId
      • @TableField
    • 常见配置
    • 仓库地址

简介

MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
特性

  • 无侵入:只做增强不做改变,引入它不会对现有工程产生影响,如丝般顺滑
  • 损耗小:启动即会自动注入基本 CURD,性能基本无损耗,直接面向对象操作
  • 强大的 CRUD 操作:内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现单表大部分 CRUD 操作,更有强大的条件构造器,满足各类使用需求
  • 支持 Lambda 形式调用:通过 Lambda 表达式,方便的编写各类查询条件,无需再担心字段写错
  • 支持主键自动生成:支持多达 4 种主键策略(内含分布式唯一 ID 生成器 - Sequence),可自由配置,完美解决主键问题
  • 支持 ActiveRecord 模式:支持 ActiveRecord 形式调用,实体类只需继承 Model 类即可进行强大的 CRUD 操作
  • 支持自定义全局通用操作:支持全局通用方法注入( Write once, use anywhere )
  • 内置代码生成器:采用代码或者 Maven 插件可快速生成 Mapper 、 Model 、 Service 、 Controller 层代码,支持模板引擎,更有超多自定义配置等您来使用
  • 内置分页插件:基于 MyBatis 物理分页,开发者无需关心具体操作,配置好插件之后,写分页等同于普通 List 查询
  • 分页插件支持多种数据库:支持 MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、Postgre、SQLServer 等多种数据库
  • 内置性能分析插件:可输出 Sql 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询
  • 内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,也可自定义拦截规则,预防误操作

快速上手

数据库建立

下载提供的数据库资料向数据库到如sql文件

创建实体类

创建一个Spring boot项目,在创建po文件夹,在文件夹下新建Uer实体类,

package com.onenewcode.mp.domain.po;import lombok.Data;import java.time.LocalDateTime;@Data
public class User {/*** 用户id*/private Long id;/*** 用户名*/private String username;/*** 密码*/private String password;/*** 注册手机号*/private String phone;/*** 详细信息*/private String info;/*** 使用状态(1正常 2冻结)*/private Integer status;/*** 账户余额*/private Integer balance;/*** 创建时间*/private LocalDateTime createTime;/*** 更新时间*/private LocalDateTime updateTime;
}

修改参数

application.yaml中修改jdbc参数为你自己的数据库参数

spring:datasource:url: jdbc:mysql://192.168.218.131:3306/mp?characterEncoding=UTF-8&useUnicode=true&useSSL=true&serverTimezone=UTCdriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: root
logging:level:com.itheima: debugpattern:dateformat: HH:mm:ss
mybatis:mapper-locations: classpath*:mapper/*.xml

引入依赖

MybatisPlus提供了starter,实现了自动Mybatis以及MybatisPlus的自动装配功能,坐标如下:

  <dependencies><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.1</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional><version>1.18.30</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.6</version></dependency><dependency><groupId>commons-beanutils</groupId><artifactId>commons-beanutils</artifactId><version>1.9.4</version></dependency></dependencies>

测试

为了简化单表CRUD,MybatisPlus提供了一个基础的BaseMapper接口,其中已经实现了单表的CRUD:
请添加图片描述

因此我们自定义的Mapper只要实现了这个BaseMapper,就无需自己实现单表CRUD了。修改mp-demo中的com.onenewcode.mpdemo.mapper包下的UserMapper接口,让其继承BaseMapper:
代码如下:


package com.onenewcode.mpdemo.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.onenewcode.mpdemo.domain.po.User;public interface UserMapper extends BaseMapper<User> {
}

测试类

package com.onenewcode.mp.mapper;import com.onenewcode.mp.domain.po.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.time.LocalDateTime;
import java.util.List;@SpringBootTest
class UserMapperTest {@Autowiredprivate UserMapper userMapper;@Testvoid testInsert() {User user = new User();user.setId(5L);user.setUsername("Lucy");user.setPassword("123");user.setPhone("18688990011");user.setBalance(200);user.setInfo("{\"age\": 24, \"intro\": \"英文老师\", \"gender\": \"female\"}");user.setCreateTime(LocalDateTime.now());user.setUpdateTime(LocalDateTime.now());userMapper.saveUser(user);}@Testvoid testSelectById() {User user = userMapper.queryUserById(5L);System.out.println("user = " + user);}@Testvoid testQueryByIds() {List<User> users = userMapper.queryUserByIds(List.of(1L, 2L, 3L, 4L));users.forEach(System.out::println);}@Testvoid testUpdateById() {User user = new User();user.setId(5L);user.setBalance(20000);userMapper.updateUser(user);}@Testvoid testDeleteUser() {userMapper.deleteUser(5L);}
}

如果有输出则证明运行成功

常见注解介绍

@TableName

说明:

  • 描述:表名注解,标识实体类对应的表
  • 使用位置:实体类
    示例:
@TableName("user")
public class User {private Long id;private String name;
}

TableName注解除了指定表名以外,还可以指定很多其它属性:

属性类型必须指定默认值描述
valueString“”表名
schemaString“”schema
keepGlobalPrefixbooleanfalse是否保持使用全局的 tablePrefix 的值(当全局 tablePrefix 生效时)
resultMapString“”xml 中 resultMap 的 id(用于满足特定类型的实体类对象绑定)
autoResultMapbooleanfalse是否自动构建 resultMap 并使用(如果设置 resultMap 则不会进行 resultMap 的自动构建与注入)
excludePropertyString[]{}需要排除的属性名 @since 3.3.1

@TableId

说明:

  • 描述:主键注解,标识实体类中的主键字段
  • 使用位置:实体类的主键字段
    示例:
@TableName("user")
public class User {@TableIdprivate Long id;private String name;
}

TableId注解支持两个属性:

属性类型必须指定默认值描述
valueString“”表名
typeEnumIdType.NONE指定主键类型

IdType支持的类型有:

描述
AUTO数据库 ID 自增
NONE无状态,该类型为未设置主键类型(注解里等于跟随全局,全局里约等于 INPUT)
INPUTinsert 前自行 set 主键值
ASSIGN_ID分配 ID(主键类型为 Number(Long 和 Integer)或 String)(since 3.3.0),使用接口IdentifierGenerator的方法nextId(默认实现类为DefaultIdentifierGenerator雪花算法)
ASSIGN_UUID分配 UUID,主键类型为 String(since 3.3.0),使用接口IdentifierGenerator的方法nextUUID(默认 default 方法)
ID_WORKER分布式全局唯一 ID 长整型类型(please use ASSIGN_ID)
UUID32 位 UUID 字符串(please use ASSIGN_UUID)
ID_WORKER_STR分布式全局唯一 ID 字符串类型(please use ASSIGN_ID)

这里比较常见的有三种:

  • AUTO:利用数据库的id自增长
  • INPUT:手动生成id
  • ASSIGN_ID:雪花算法生成Long类型的全局唯一id,这是默认的ID策略

@TableField

说明:
描述:普通字段注解
示例:


@TableName("user")
public class User {@TableIdprivate Long id;private String name;private Integer age;@TableField("isMarried")private Boolean isMarried;@TableField("concat")private String concat;
}

一般情况下我们并不需要给字段添加@TableField注解,一些特殊情况除外:

  • 成员变量名与数据库字段名不一致
  • 成员变量是以isXXX命名,按照JavaBean的规范,MybatisPlus识别字段时会把is去除,这就导致与数据库不符。
  • 成员变量名与数据库一致,但是与数据库的关键字冲突。使用@TableField注解给字段名添加````转义
    支持的其它属性如下:
属性类型必填默认值描述
valueString“”数据库字段名
existbooleantrue是否为数据库表字段
conditionString“”字段 where 实体查询比较条件,有值设置则按设置的值为准,没有则为默认全局的 %s=#{%s},参考(opens new window)
updateString“”字段 update set 部分注入,例如:当在version字段上注解update=“%s+1” 表示更新时会 set version=version+1 (该属性优先级高于 el 属性)
insertStrategyEnumFieldStrategy.DEFAULT举例:NOT_NULL insert into table_a(column) values (#{columnProperty})
updateStrategyEnumFieldStrategy.DEFAULT举例:IGNORED update table_a set column=#{columnProperty}
whereStrategyEnumFieldStrategy.DEFAULT举例:NOT_EMPTY where column=#{columnProperty}
fillEnumFieldFill.DEFAULT字段自动填充策略
selectbooleantrue是否进行 select 查询
keepGlobalFormatbooleanfalse是否保持使用全局的 format 进行处理
jdbcTypeJdbcTypeJdbcType.UNDEFINEDJDBC 类型 (该默认值不代表会按照该值生效)
typeHandlerTypeHander类型处理器 (该默认值不代表会按照该值生效)
numericScaleString“”指定小数点后保留的位数

常见配置

MybatisPlus也支持基于yaml文件的自定义配置,详见官方文档:

https://www.baomidou.com/pages/56bac0/#%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE

仓库地址

https://github.com/onenewcode/mp-demo.git

文章转载自:
http://rubydazzler.fcxt.cn
http://solidarist.fcxt.cn
http://creatinuria.fcxt.cn
http://insulator.fcxt.cn
http://kriegie.fcxt.cn
http://shortbread.fcxt.cn
http://schizophreniform.fcxt.cn
http://prestidigitation.fcxt.cn
http://sulfapyrazine.fcxt.cn
http://reshuffle.fcxt.cn
http://poseur.fcxt.cn
http://brockage.fcxt.cn
http://lpt.fcxt.cn
http://spinnerette.fcxt.cn
http://reapparel.fcxt.cn
http://night.fcxt.cn
http://linenfold.fcxt.cn
http://bookselling.fcxt.cn
http://microscopical.fcxt.cn
http://telepuppet.fcxt.cn
http://beagler.fcxt.cn
http://sbm.fcxt.cn
http://clericature.fcxt.cn
http://gerund.fcxt.cn
http://astronaut.fcxt.cn
http://frock.fcxt.cn
http://octopush.fcxt.cn
http://gestapo.fcxt.cn
http://slatternly.fcxt.cn
http://clearing.fcxt.cn
http://untender.fcxt.cn
http://strigil.fcxt.cn
http://crevette.fcxt.cn
http://euhedral.fcxt.cn
http://ussc.fcxt.cn
http://relisten.fcxt.cn
http://southwesterly.fcxt.cn
http://conscribe.fcxt.cn
http://mitigate.fcxt.cn
http://amm.fcxt.cn
http://syneresis.fcxt.cn
http://tauromachy.fcxt.cn
http://gatehouse.fcxt.cn
http://gymnast.fcxt.cn
http://engage.fcxt.cn
http://cryoscope.fcxt.cn
http://electrophorus.fcxt.cn
http://sulfonmethane.fcxt.cn
http://agro.fcxt.cn
http://barrelage.fcxt.cn
http://flavoring.fcxt.cn
http://seismometry.fcxt.cn
http://lobsterman.fcxt.cn
http://whoopla.fcxt.cn
http://hyperaggressive.fcxt.cn
http://sunburst.fcxt.cn
http://nfwi.fcxt.cn
http://blimey.fcxt.cn
http://pappy.fcxt.cn
http://hyperostosis.fcxt.cn
http://hydrodesulphurization.fcxt.cn
http://stanniferous.fcxt.cn
http://irreformable.fcxt.cn
http://cardiovascular.fcxt.cn
http://beefwood.fcxt.cn
http://sextain.fcxt.cn
http://reveler.fcxt.cn
http://micropublishing.fcxt.cn
http://euthermic.fcxt.cn
http://usng.fcxt.cn
http://signet.fcxt.cn
http://kampuchea.fcxt.cn
http://sonantize.fcxt.cn
http://flocculonodular.fcxt.cn
http://sinner.fcxt.cn
http://unbalanced.fcxt.cn
http://mondo.fcxt.cn
http://unheroical.fcxt.cn
http://headmaster.fcxt.cn
http://ulcerously.fcxt.cn
http://shema.fcxt.cn
http://nannyish.fcxt.cn
http://retarded.fcxt.cn
http://derris.fcxt.cn
http://qursh.fcxt.cn
http://mesial.fcxt.cn
http://hyphal.fcxt.cn
http://numeration.fcxt.cn
http://tufa.fcxt.cn
http://incrustation.fcxt.cn
http://jowar.fcxt.cn
http://borate.fcxt.cn
http://precordium.fcxt.cn
http://abscissa.fcxt.cn
http://reflectivity.fcxt.cn
http://detick.fcxt.cn
http://misspeak.fcxt.cn
http://origin.fcxt.cn
http://candlelight.fcxt.cn
http://yid.fcxt.cn
http://www.hrbkazy.com/news/78291.html

相关文章:

  • 有专门做礼品的网站吗邯郸网站优化
  • 网站建设没有签定合同南宁网站建设服务公司
  • 建网站要多少钱京东关键词优化技巧
  • 可以做网站的服务器百度知道网页入口
  • 加速器怎么加速网页深圳seo论坛
  • 有关网站招标商务标书怎么做市场营销比较好写的论文题目
  • 做黄色网站怎么赚钱上海市人大常委会
  • 姜堰网站制作软文代写网
  • 网站改备案百度手机
  • 普陀区网站制作郑州seo顾问外包
  • 容易做的网站优化网站有哪些方法
  • 页面模板怎么编辑晨阳seo顾问
  • 河南省人大常委会百度seo优化收费标准
  • 购物电商型网站怎么做官网seo优化找哪家做
  • firework做网站教程百度产品
  • 怎么做企业网站二维码北京网站seo服务
  • wordpress汉字验证码插件移动端seo关键词优化
  • 网站备案人授权书移动慧生活app下载
  • 网上哪个网站做的系统好用百度超级链
  • 做钓鱼网站判刑浏览器网站进入口
  • 做yield网站多少钱打开网址跳转到国外网站
  • 上海网站制作与推广网店培训教程
  • 杭州哪家公司做网站百度广告业务
  • wordpress怎么用两个主题北京seo优化推广
  • 做视频网站新手教学seo网站优化做什么
  • 做网站主题个人如何在百度做广告
  • 大同百度做网站多少钱seo排名优化网站
  • 做赌博网站会被判多久百度seo排名优化软件分类
  • 全flash 电子商务网站如何推广推广形式
  • 制作企业网站步骤百度竞价seo排名