Mybatis Generator 使用手册
第一章 什么是Mybatis Generator?
MyBatis Generator Core – Introduction to MyBatis Generator
MyBatis生成器(MBG)是MyBatis框架的代码生成工具。它支持为所有版本的MyBatis生成代码,通过解析数据库表(或多个表)结构,自动生成用于访问这些表的相关组件。这有效减轻了手动配置对象和配置文件以实现数据库表交互的初始繁琐工作。MBG主要致力于简化大量基础性的数据库操作——即常见的增删改查(CRUD)操作。但对于涉及联合查询或存储过程等复杂场景,仍需开发者手动编写SQL和对象。
尽管限制新版本的MBG可以生成带注解版本(不包含xml)的Java代码,但是注解实现复杂场景(表join查询)时不是太方便,所以一般推荐使用传统版本的xml配置文件进行映射。
第二章 Mybatis Generator 各版本的功能?
我们主要使用的两个版本:
MyBatis3DynamicSQL:可生成不带xml配置的Java注解版代码。
Mybatis3:生成传统的使用XML进行映射的访问数据库代码。
| Runtime | MyBatis Generator Version | MyBatis Version | MyBatis Dynamic SQL Version |
|---|---|---|---|
| MyBatis3, MyBatis3Simple | Any | 3.0+ | N/A |
| MyBatis3DynamicSQL | 1.3.6 - 1.3.7 | 3.4.2+ | 1.1.0 - 1.2.1 |
| MyBatis3DynamicSQL, MyBatis3Kotlin | 1.4.0 | 3.4.2+ | 1.1.3+ |
| MyBatis3DynamicSQL | 1.4.1+ | 3.4.2+ | 1.3.1+ |
| MyBatis3Kotlin | 1.4.1+ | 3.4.2+ | 1.4.0+ |
通常我们使用maven插件来进行代码的生成,多次运行代码Mybatis Generator的处理方式。
注意:当Mapper.java或者Mapper.xml有改动时,默认情况下时自动合并xml文件(保留已经修改的内容),但是Mapper.java会生成一个新的带版本的java文件(比如Mapper.java.1),需要手动合并。
比较推荐的做法是:使用原生的生成文件不做任何改动,需要修改时使用MapperExt.java, MapperExt.xml进行修改。这样省去了合并代码的工作。
第三章 怎样使用Mybatis Genrator?
3.1.引入依赖
<dependencies><dependency><groupId>jakarta.annotation</groupId><artifactId>jakarta.annotation-api</artifactId><version>2.1.1</version><scope>provided</scope></dependency><!-- MyBatis 核心依赖 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.13</version></dependency><!-- MySQL 连接器依赖 --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.4.0</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId><version>5.11.4</version><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.4.2</version><configuration><configurationFile>src/main/resources/mybatis-generator-config.xml</configurationFile></configuration><dependencies><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.4.0</version></dependency></dependencies></plugin></plugins></build>
此处数据库默认使用的MySQL,所以引入mysql的driver. 同时使用maven运行mybatis generator,加入maven mybatis-generator-maven-plugin.
3.2 加入配置文件
配置文件名称: mybatis-generator-config.xml
<!DOCTYPE generatorConfiguration PUBLIC"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration><context id="mybatis3" targetRuntime="MyBatis3"><jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"connectionURL="jdbc:mysql://localhost:3306/test_db"userId="user_name"password="my_password"/><javaModelGenerator targetPackage="com.my.model" targetProject="src/main/java"/><sqlMapGenerator targetPackage="com.my.mapper" targetProject="src/main/resources"/><javaClientGenerator type="XMLMAPPER" targetPackage="com.my.mapper" targetProject="src/main/java"/><table tableName="t_user" domainObjectName="User" /><table tableName="t_teacher" domainObjectName="Teacher" /><table tableName="t_student" domainObjectName="Student" /></context>
</generatorConfiguration>
根据配置文件中的内容,修改自己的数据库连接信息,需要放置的包名称,需要生成的表名称。
3.运行命令
mvn mybatis-generator:generate
然后代码就自动生成了。就可以完美的进行单表操作了。
第四章 生成代码的使用?
生成的Mapper.xml就不看了,写得很棒很专业。我们需要看看Mapper.java 和Example类,这样可以知道生成的类怎样使用?
4.1 UserExample类
下面以User的Example类进行说明,该类的含义和使用。
package com.my.model;import java.util.ArrayList;
import java.util.Date;
import java.util.List;public class UserExample {/*** This field was generated by MyBatis Generator.* This field corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/protected String orderByClause;/*** This field was generated by MyBatis Generator.* This field corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/protected boolean distinct;/*** This field was generated by MyBatis Generator.* This field corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/protected List<Criteria> oredCriteria;/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public UserExample() {oredCriteria = new ArrayList<>();}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public void setOrderByClause(String orderByClause) {this.orderByClause = orderByClause;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public String getOrderByClause() {return orderByClause;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public void setDistinct(boolean distinct) {this.distinct = distinct;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public boolean isDistinct() {return distinct;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public List<Criteria> getOredCriteria() {return oredCriteria;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public void or(Criteria criteria) {oredCriteria.add(criteria);}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public Criteria or() {Criteria criteria = createCriteriaInternal();oredCriteria.add(criteria);return criteria;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public Criteria createCriteria() {Criteria criteria = createCriteriaInternal();if (oredCriteria.size() == 0) {oredCriteria.add(criteria);}return criteria;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/protected Criteria createCriteriaInternal() {Criteria criteria = new Criteria();return criteria;}/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public void clear() {oredCriteria.clear();orderByClause = null;distinct = false;}/*** This class was generated by MyBatis Generator.* This class corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/protected abstract static class GeneratedCriteria {protected List<Criterion> criteria;protected GeneratedCriteria() {super();criteria = new ArrayList<>();}public boolean isValid() {return criteria.size() > 0;}public List<Criterion> getAllCriteria() {return criteria;}public List<Criterion> getCriteria() {return criteria;}protected void addCriterion(String condition) {if (condition == null) {throw new RuntimeException("Value for condition cannot be null");}criteria.add(new Criterion(condition));}protected void addCriterion(String condition, Object value, String property) {if (value == null) {throw new RuntimeException("Value for " + property + " cannot be null");}criteria.add(new Criterion(condition, value));}protected void addCriterion(String condition, Object value1, Object value2, String property) {if (value1 == null || value2 == null) {throw new RuntimeException("Between values for " + property + " cannot be null");}criteria.add(new Criterion(condition, value1, value2));}public Criteria andUserIdIsNull() {addCriterion("USER_ID is null");return (Criteria) this;}public Criteria andUserIdIsNotNull() {addCriterion("USER_ID is not null");return (Criteria) this;}public Criteria andUserIdEqualTo(Integer value) {addCriterion("USER_ID =", value, "userId");return (Criteria) this;}public Criteria andUserIdNotEqualTo(Integer value) {addCriterion("USER_ID <>", value, "userId");return (Criteria) this;}public Criteria andUserIdGreaterThan(Integer value) {addCriterion("USER_ID >", value, "userId");return (Criteria) this;}public Criteria andUserIdGreaterThanOrEqualTo(Integer value) {addCriterion("USER_ID >=", value, "userId");return (Criteria) this;}public Criteria andUserIdLessThan(Integer value) {addCriterion("USER_ID <", value, "userId");return (Criteria) this;}public Criteria andUserIdLessThanOrEqualTo(Integer value) {addCriterion("USER_ID <=", value, "userId");return (Criteria) this;}public Criteria andUserIdIn(List<Integer> values) {addCriterion("USER_ID in", values, "userId");return (Criteria) this;}public Criteria andUserIdNotIn(List<Integer> values) {addCriterion("USER_ID not in", values, "userId");return (Criteria) this;}public Criteria andUserIdBetween(Integer value1, Integer value2) {addCriterion("USER_ID between", value1, value2, "userId");return (Criteria) this;}public Criteria andUserIdNotBetween(Integer value1, Integer value2) {addCriterion("USER_ID not between", value1, value2, "userId");return (Criteria) this;}public Criteria andUserNameIsNull() {addCriterion("USER_NAME is null");return (Criteria) this;}public Criteria andUserNameIsNotNull() {addCriterion("USER_NAME is not null");return (Criteria) this;}public Criteria andUserNameEqualTo(String value) {addCriterion("USER_NAME =", value, "userName");return (Criteria) this;}public Criteria andUserNameNotEqualTo(String value) {addCriterion("USER_NAME <>", value, "userName");return (Criteria) this;}public Criteria andUserNameGreaterThan(String value) {addCriterion("USER_NAME >", value, "userName");return (Criteria) this;}public Criteria andUserNameGreaterThanOrEqualTo(String value) {addCriterion("USER_NAME >=", value, "userName");return (Criteria) this;}public Criteria andUserNameLessThan(String value) {addCriterion("USER_NAME <", value, "userName");return (Criteria) this;}public Criteria andUserNameLessThanOrEqualTo(String value) {addCriterion("USER_NAME <=", value, "userName");return (Criteria) this;}public Criteria andUserNameLike(String value) {addCriterion("USER_NAME like", value, "userName");return (Criteria) this;}public Criteria andUserNameNotLike(String value) {addCriterion("USER_NAME not like", value, "userName");return (Criteria) this;}public Criteria andUserNameIn(List<String> values) {addCriterion("USER_NAME in", values, "userName");return (Criteria) this;}public Criteria andUserNameNotIn(List<String> values) {addCriterion("USER_NAME not in", values, "userName");return (Criteria) this;}public Criteria andUserNameBetween(String value1, String value2) {addCriterion("USER_NAME between", value1, value2, "userName");return (Criteria) this;}public Criteria andUserNameNotBetween(String value1, String value2) {addCriterion("USER_NAME not between", value1, value2, "userName");return (Criteria) this;}public Criteria andAgeIsNull() {addCriterion("AGE is null");return (Criteria) this;}public Criteria andAgeIsNotNull() {addCriterion("AGE is not null");return (Criteria) this;}public Criteria andAgeEqualTo(Integer value) {addCriterion("AGE =", value, "age");return (Criteria) this;}public Criteria andAgeNotEqualTo(Integer value) {addCriterion("AGE <>", value, "age");return (Criteria) this;}public Criteria andAgeGreaterThan(Integer value) {addCriterion("AGE >", value, "age");return (Criteria) this;}public Criteria andAgeGreaterThanOrEqualTo(Integer value) {addCriterion("AGE >=", value, "age");return (Criteria) this;}public Criteria andAgeLessThan(Integer value) {addCriterion("AGE <", value, "age");return (Criteria) this;}public Criteria andAgeLessThanOrEqualTo(Integer value) {addCriterion("AGE <=", value, "age");return (Criteria) this;}public Criteria andAgeIn(List<Integer> values) {addCriterion("AGE in", values, "age");return (Criteria) this;}public Criteria andAgeNotIn(List<Integer> values) {addCriterion("AGE not in", values, "age");return (Criteria) this;}public Criteria andAgeBetween(Integer value1, Integer value2) {addCriterion("AGE between", value1, value2, "age");return (Criteria) this;}public Criteria andAgeNotBetween(Integer value1, Integer value2) {addCriterion("AGE not between", value1, value2, "age");return (Criteria) this;}public Criteria andCreatedTimeIsNull() {addCriterion("CREATED_TIME is null");return (Criteria) this;}public Criteria andCreatedTimeIsNotNull() {addCriterion("CREATED_TIME is not null");return (Criteria) this;}public Criteria andCreatedTimeEqualTo(Date value) {addCriterion("CREATED_TIME =", value, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeNotEqualTo(Date value) {addCriterion("CREATED_TIME <>", value, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeGreaterThan(Date value) {addCriterion("CREATED_TIME >", value, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeGreaterThanOrEqualTo(Date value) {addCriterion("CREATED_TIME >=", value, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeLessThan(Date value) {addCriterion("CREATED_TIME <", value, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeLessThanOrEqualTo(Date value) {addCriterion("CREATED_TIME <=", value, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeIn(List<Date> values) {addCriterion("CREATED_TIME in", values, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeNotIn(List<Date> values) {addCriterion("CREATED_TIME not in", values, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeBetween(Date value1, Date value2) {addCriterion("CREATED_TIME between", value1, value2, "createdTime");return (Criteria) this;}public Criteria andCreatedTimeNotBetween(Date value1, Date value2) {addCriterion("CREATED_TIME not between", value1, value2, "createdTime");return (Criteria) this;}public Criteria andCreatedByIsNull() {addCriterion("CREATED_BY is null");return (Criteria) this;}public Criteria andCreatedByIsNotNull() {addCriterion("CREATED_BY is not null");return (Criteria) this;}public Criteria andCreatedByEqualTo(String value) {addCriterion("CREATED_BY =", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByNotEqualTo(String value) {addCriterion("CREATED_BY <>", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByGreaterThan(String value) {addCriterion("CREATED_BY >", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByGreaterThanOrEqualTo(String value) {addCriterion("CREATED_BY >=", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByLessThan(String value) {addCriterion("CREATED_BY <", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByLessThanOrEqualTo(String value) {addCriterion("CREATED_BY <=", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByLike(String value) {addCriterion("CREATED_BY like", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByNotLike(String value) {addCriterion("CREATED_BY not like", value, "createdBy");return (Criteria) this;}public Criteria andCreatedByIn(List<String> values) {addCriterion("CREATED_BY in", values, "createdBy");return (Criteria) this;}public Criteria andCreatedByNotIn(List<String> values) {addCriterion("CREATED_BY not in", values, "createdBy");return (Criteria) this;}public Criteria andCreatedByBetween(String value1, String value2) {addCriterion("CREATED_BY between", value1, value2, "createdBy");return (Criteria) this;}public Criteria andCreatedByNotBetween(String value1, String value2) {addCriterion("CREATED_BY not between", value1, value2, "createdBy");return (Criteria) this;}public Criteria andUpdatedTimeIsNull() {addCriterion("UPDATED_TIME is null");return (Criteria) this;}public Criteria andUpdatedTimeIsNotNull() {addCriterion("UPDATED_TIME is not null");return (Criteria) this;}public Criteria andUpdatedTimeEqualTo(Date value) {addCriterion("UPDATED_TIME =", value, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeNotEqualTo(Date value) {addCriterion("UPDATED_TIME <>", value, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeGreaterThan(Date value) {addCriterion("UPDATED_TIME >", value, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeGreaterThanOrEqualTo(Date value) {addCriterion("UPDATED_TIME >=", value, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeLessThan(Date value) {addCriterion("UPDATED_TIME <", value, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeLessThanOrEqualTo(Date value) {addCriterion("UPDATED_TIME <=", value, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeIn(List<Date> values) {addCriterion("UPDATED_TIME in", values, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeNotIn(List<Date> values) {addCriterion("UPDATED_TIME not in", values, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeBetween(Date value1, Date value2) {addCriterion("UPDATED_TIME between", value1, value2, "updatedTime");return (Criteria) this;}public Criteria andUpdatedTimeNotBetween(Date value1, Date value2) {addCriterion("UPDATED_TIME not between", value1, value2, "updatedTime");return (Criteria) this;}public Criteria andUpdatedByIsNull() {addCriterion("UPDATED_BY is null");return (Criteria) this;}public Criteria andUpdatedByIsNotNull() {addCriterion("UPDATED_BY is not null");return (Criteria) this;}public Criteria andUpdatedByEqualTo(String value) {addCriterion("UPDATED_BY =", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByNotEqualTo(String value) {addCriterion("UPDATED_BY <>", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByGreaterThan(String value) {addCriterion("UPDATED_BY >", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByGreaterThanOrEqualTo(String value) {addCriterion("UPDATED_BY >=", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByLessThan(String value) {addCriterion("UPDATED_BY <", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByLessThanOrEqualTo(String value) {addCriterion("UPDATED_BY <=", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByLike(String value) {addCriterion("UPDATED_BY like", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByNotLike(String value) {addCriterion("UPDATED_BY not like", value, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByIn(List<String> values) {addCriterion("UPDATED_BY in", values, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByNotIn(List<String> values) {addCriterion("UPDATED_BY not in", values, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByBetween(String value1, String value2) {addCriterion("UPDATED_BY between", value1, value2, "updatedBy");return (Criteria) this;}public Criteria andUpdatedByNotBetween(String value1, String value2) {addCriterion("UPDATED_BY not between", value1, value2, "updatedBy");return (Criteria) this;}}/*** This class was generated by MyBatis Generator.* This class corresponds to the database table user** @mbg.generated do_not_delete_during_merge Sat Mar 08 07:25:49 CST 2025*/public static class Criteria extends GeneratedCriteria {protected Criteria() {super();}}/*** This class was generated by MyBatis Generator.* This class corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/public static class Criterion {private String condition;private Object value;private Object secondValue;private boolean noValue;private boolean singleValue;private boolean betweenValue;private boolean listValue;private String typeHandler;public String getCondition() {return condition;}public Object getValue() {return value;}public Object getSecondValue() {return secondValue;}public boolean isNoValue() {return noValue;}public boolean isSingleValue() {return singleValue;}public boolean isBetweenValue() {return betweenValue;}public boolean isListValue() {return listValue;}public String getTypeHandler() {return typeHandler;}protected Criterion(String condition) {super();this.condition = condition;this.typeHandler = null;this.noValue = true;}protected Criterion(String condition, Object value, String typeHandler) {super();this.condition = condition;this.value = value;this.typeHandler = typeHandler;if (value instanceof List<?>) {this.listValue = true;} else {this.singleValue = true;}}protected Criterion(String condition, Object value) {this(condition, value, null);}protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {super();this.condition = condition;this.value = value;this.secondValue = secondValue;this.typeHandler = typeHandler;this.betweenValue = true;}protected Criterion(String condition, Object value, Object secondValue) {this(condition, value, secondValue, null);}}
}
这个Example类,主要是使用Critiertion(单个的查询条件)和Critiera(多个查询条件)的封装类。
- 查询条件Critera --> List<Criterition>
- setDistinct 设置是否去重
- setOrderByClause(**) 设置排序的字段
使用它的方式如下:
UserExample example = new UserExample();
example.createCretiar().andCreatedByEqualTo("jack.zhang"); // 构建第一个and条件连接的查询链
example.or().anUserNameIsEqualTo("name"); // 构建第二个包含or里的 ( and 条件链)
example.setDistinct(true) // 设置去重
example.setOrderByClause("USER_NAME DESC"); // 设置排序字段
生成的SQL语句如下:
select distinct USER_ID, USER_NAME, AGE, CREATED_TIME, CREATED_BY
from user
WHERE ( CREATED_BY = ? ) or ( USER_NAME = ? )
order by USER_ID ASC
4.2 UserMapper.java类
package com.keyrus.mapper;import com.keyrus.model.User;
import com.keyrus.model.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;public interface UserMapper {/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/long countByExample(UserExample example);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int deleteByExample(UserExample example);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int deleteByPrimaryKey(Integer userId);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int insert(User row);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int insertSelective(User row);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/List<User> selectByExample(UserExample example);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/User selectByPrimaryKey(Integer userId);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int updateByExampleSelective(@Param("row") User row, @Param("example") UserExample example);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int updateByExample(@Param("row") User row, @Param("example") UserExample example);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int updateByPrimaryKeySelective(User row);/*** This method was generated by MyBatis Generator.* This method corresponds to the database table user** @mbg.generated Sat Mar 08 07:25:49 CST 2025*/int updateByPrimaryKey(User row);
}
按照新增/修改/查询/删除的顺序,方法归纳如下:
insert(User user) 插入整个User对象;
insertSelective(User user) 插入部分字段;
updateByPrimaryKey(User user) 根据主键更新User;
updateByPrimaryKeySelective (User user) 根据主键部分更新User的字段;
updateByExampleSelective(User user, UserExample example) 根据example条件筛选出记录进行部分user字段的更新。
selectByPrimaryKey(id) 根据主键查询User;
selectByExample(UserExample exapmle) 根据example条件筛选查询User;
countByExample(UserExample example) 根据example条件查询统计记录数目;
deleteByPrimaryKey(id) 根据主键进行删除单条记录;
deleteByExample(UserExample example) 根据example条件筛选出多条记录进行删除;
基本上上面的四类方法,包含了日常单表的所有操作。
有复杂的表与表直接的操作,需要自己手写去完成。
相关文章:
Mybatis Generator 使用手册
第一章 什么是Mybatis Generator? MyBatis Generator Core – Introduction to MyBatis Generator MyBatis生成器(MBG)是MyBatis框架的代码生成工具。它支持为所有版本的MyBatis生成代码,通过解析数据库表(或多个表&…...
快乐数 力扣202
一、题目 编写一个算法来判断一个数 n 是不是快乐数。 「快乐数」 定义为: 对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和。然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。如果这个过程 结果为 1&…...
SPA单页面应用优化SEO
1.SSR服务端渲染 将组件或页面通过服务器生成html,再返回给浏览器,如nuxt.js或vue-server-renderer const Vue require(vue); const server require(express)(); const renderer require(vue-server-renderer).createRenderer();const vueApp new …...
城市霓虹灯夜景拍照后期Lr调色教程,手机滤镜PS+Lightroom预设下载!
调色教程 在城市霓虹灯夜景拍摄中,由于现场光线复杂等因素,照片可能无法完全呈现出当时的视觉感受。通过 Lr 调色,可以弥补拍摄时的不足。例如,运用基本调整面板中的曝光、对比度、阴影等工具,可以处理出画面的整体明暗…...
通领科技冲刺北交所
高质量增长奔赴产业新征程 日前,通领科技已正式启动在北交所的 IPO 进程,期望借助资本市场的力量,加速技术升级,推动全球化战略布局。这一举措不仅展现了中国汽车零部件企业的强大实力,也预示着行业转型升级的新突破。…...
隐私保护在 Facebook 用户身份验证中的应用
在这个数字化的时代,个人隐私保护成为了公众关注的焦点。社交媒体巨头 Facebook 作为全球最大的社交平台之一,拥有数十亿用户,其在用户身份验证过程中对隐私保护的重视程度直接影响着用户的安全感和信任度。本文将探讨 Facebook 在用户身份验…...
深度学习/强化学习调参技巧
深度调优策略 1. 学习率调整 技巧:学习率是最重要的超参数之一。过大可能导致训练不稳定,过小则收敛速度慢。可以使用学习率衰减(Learning Rate Decay)或自适应学习率方法(如Adam、RMSprop)来动态调整学习…...
python面试常见题目
1、python 有几种数据类型 数字:整形 (int),浮点型 (float)布尔 ( bool):false true字符串 (string)列表 (list)元组 (tuple)字典 &…...
echarts折线图设置背景颜色:X轴和Y轴组成部分背景色
echarts折线图设置背景颜色 关键代码 splitArea: {show: true,areaStyle: {color: [#F2F2F2],},},完整代码位置显示 yAxis: {type: value,boundaryGap: [0, 100%],max: 1,interval: 1,// 于设置y轴的字体axisLabel: {show: false, //这里的show用于设置是否显示y轴下的字体 默…...
文本处理Bert面试内容整理-BERT的应用场景有哪些?
BERT(Bidirectional Encoder Representations from Transformers)在多个自然语言处理(NLP)任务中表现出了强大的能力。由于其能够捕捉双向上下文信息和强大的迁移学习能力,BERT广泛应用于各种NLP场景。以下是BERT的一些典型应用场景: 1. 文本分类 文本分类任务旨在将文本…...
【愚公系列】《Python网络爬虫从入门到精通》045-Charles的SSL证书的安装
标题详情作者简介愚公搬代码头衔华为云特约编辑,华为云云享专家,华为开发者专家,华为产品云测专家,CSDN博客专家,CSDN商业化专家,阿里云专家博主,阿里云签约作者,腾讯云优秀博主&…...
manus对比ChatGPT-Deep reaserch进行研究类学术相关数据分析!谁更胜一筹?
没有账号,只能挑选一个案例 一夜之间被这个用全英文介绍全华班出品的新爆款国产AI产品的小胖刷频。白天还没有切换语言的选项,晚上就加上了。简单看了看团队够成,使用很长实践的Monica创始人也在其中。逐渐可以理解,重心放在海外产…...
20250307确认荣品PRO-RK3566开发板在Android13下的以太网络共享功能
20250307确认荣品PRO-RK3566开发板在Android13下的以太网络共享功能 2025/3/7 13:56 缘起:我司地面站需要实现“太网络共享功能”功能。电脑PC要像连接WIFI热点一样连接在Android设备/平板电脑上来实现上网功能/数据传输。 Android设备/平板电脑通过4G/WIFI来上网。…...
Unity Job系统详解原理和基础应用处理大量物体位置
概述 该脚本使用 Unity Job System 和 Burst Compiler 高效管理大量剑对象的位移计算与坐标更新。通过双缓冲技术实现无锁并行计算,适用于需要高性能批量处理Transform的场景。 核心类 SwordManager 成员变量 变量名类型说明swordPrefabGameObject剑对象预制体_d…...
高效编程指南:PyCharm与DeepSeek的完美结合
DeepSeek接入Pycharm 前几天DeepSeek的充值窗口又悄悄的开放了,这也就意味着我们又可以丝滑的使用DeepSeek的API进行各种辅助性工作了。本文我们来聊聊如何在代码编辑器中使用DeepSeek自动生成代码。 注:本文适用于所有的JetBrains开发工具,…...
Facebook 的隐私保护数据存储方案研究
Facebook 的隐私保护数据存储方案研究 在这个信息爆炸的时代,数据隐私保护已成为公众关注的热点。Facebook,作为全球最大的社交媒体平台之一,承载着海量用户数据,其隐私保护措施和数据存储方案对于维护用户隐私至关重要。本文将深…...
c#面试题整理
1.如何保持数据库的完整性,一致性 最好的方法:数据库约束(check,unique,主键,外键,默认,非空) 其次是:用触发器 最后:才是自己些业务逻辑,这个效率低 2.事…...
车载以太网测试-4车载以太网如何进行通信的?
1 摘要 车载以太网的数据传输与接收遵循分层网络架构(如OSI模型或TCP/IP模型),从应用层到物理层需要逐层封装与解封装。本文将对车载以太网的数据传输流程进行介绍。 2 以太网通信过程(封装与解封装) 2.1 发送端流程…...
R软件线性模型与lmer混合效应模型对生态学龙类智力测试数据层级结构应用
全文链接:https://tecdat.cn/?p40925 在生态与生物学研究中,数据常呈现复杂结构特征。例如不同种群、采样点或时间序列的观测数据间往往存在相关性(点击文末“阅读原文”获取完整代码、数据、文档)。 传统线性模型在处理这类非独…...
WIFI ESP8266以及基础功能介绍
芯片一旦烧写了程序就不可以使用AT指令集,需要重新刷回AT指令库才可以使用 wifi的通信频段是2.4G免费频段。 AT指令 AT(attention)command set.AT指令集或命令集,一般称为AT指令 海斯命令集:Hayes command set 默认…...
TDengine 快速体验(Docker 镜像方式)
简介 TDengine 可以通过安装包、Docker 镜像 及云服务快速体验 TDengine 的功能,本节首先介绍如何通过 Docker 快速体验 TDengine,然后介绍如何在 Docker 环境下体验 TDengine 的写入和查询功能。如果你不熟悉 Docker,请使用 安装包的方式快…...
在rocky linux 9.5上在线安装 docker
前面是指南,后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...
从深圳崛起的“机器之眼”:赴港乐动机器人的万亿赛道赶考路
进入2025年以来,尽管围绕人形机器人、具身智能等机器人赛道的质疑声不断,但全球市场热度依然高涨,入局者持续增加。 以国内市场为例,天眼查专业版数据显示,截至5月底,我国现存在业、存续状态的机器人相关企…...
Linux-07 ubuntu 的 chrome 启动不了
文章目录 问题原因解决步骤一、卸载旧版chrome二、重新安装chorme三、启动不了,报错如下四、启动不了,解决如下 总结 问题原因 在应用中可以看到chrome,但是打不开(说明:原来的ubuntu系统出问题了,这个是备用的硬盘&a…...
高防服务器能够抵御哪些网络攻击呢?
高防服务器作为一种有着高度防御能力的服务器,可以帮助网站应对分布式拒绝服务攻击,有效识别和清理一些恶意的网络流量,为用户提供安全且稳定的网络环境,那么,高防服务器一般都可以抵御哪些网络攻击呢?下面…...
聊一聊接口测试的意义有哪些?
目录 一、隔离性 & 早期测试 二、保障系统集成质量 三、验证业务逻辑的核心层 四、提升测试效率与覆盖度 五、系统稳定性的守护者 六、驱动团队协作与契约管理 七、性能与扩展性的前置评估 八、持续交付的核心支撑 接口测试的意义可以从四个维度展开,首…...
Go 语言并发编程基础:无缓冲与有缓冲通道
在上一章节中,我们了解了 Channel 的基本用法。本章将重点分析 Go 中通道的两种类型 —— 无缓冲通道与有缓冲通道,它们在并发编程中各具特点和应用场景。 一、通道的基本分类 类型定义形式特点无缓冲通道make(chan T)发送和接收都必须准备好࿰…...
RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)
RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发,后来由Pivotal Software Inc.(现为VMware子公司)接管。RabbitMQ 是一个开源的消息代理和队列服务器,用 Erlang 语言编写。广泛应用于各种分布…...
宇树科技,改名了!
提到国内具身智能和机器人领域的代表企业,那宇树科技(Unitree)必须名列其榜。 最近,宇树科技的一项新变动消息在业界引发了不少关注和讨论,即: 宇树向其合作伙伴发布了一封公司名称变更函称,因…...
基于Java+VUE+MariaDB实现(Web)仿小米商城
仿小米商城 环境安装 nodejs maven JDK11 运行 mvn clean install -DskipTestscd adminmvn spring-boot:runcd ../webmvn spring-boot:runcd ../xiaomi-store-admin-vuenpm installnpm run servecd ../xiaomi-store-vuenpm installnpm run serve 注意:运行前…...
