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

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进行映射的访问数据库代码。

RuntimeMyBatis Generator VersionMyBatis VersionMyBatis Dynamic SQL Version
MyBatis3, MyBatis3SimpleAny3.0+N/A
MyBatis3DynamicSQL1.3.6 - 1.3.73.4.2+1.1.0 - 1.2.1
MyBatis3DynamicSQL, MyBatis3Kotlin1.4.03.4.2+1.1.3+
MyBatis3DynamicSQL1.4.1+3.4.2+1.3.1+
MyBatis3Kotlin1.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&#xff1f; MyBatis Generator Core – Introduction to MyBatis Generator MyBatis生成器&#xff08;MBG&#xff09;是MyBatis框架的代码生成工具。它支持为所有版本的MyBatis生成代码&#xff0c;通过解析数据库表&#xff08;或多个表&…...

快乐数 力扣202

一、题目 编写一个算法来判断一个数 n 是不是快乐数。 「快乐数」 定义为&#xff1a; 对于一个正整数&#xff0c;每一次将该数替换为它每个位置上的数字的平方和。然后重复这个过程直到这个数变为 1&#xff0c;也可能是 无限循环 但始终变不到 1。如果这个过程 结果为 1&…...

SPA单页面应用优化SEO

1.SSR服务端渲染 将组件或页面通过服务器生成html&#xff0c;再返回给浏览器&#xff0c;如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预设下载!

调色教程 在城市霓虹灯夜景拍摄中&#xff0c;由于现场光线复杂等因素&#xff0c;照片可能无法完全呈现出当时的视觉感受。通过 Lr 调色&#xff0c;可以弥补拍摄时的不足。例如&#xff0c;运用基本调整面板中的曝光、对比度、阴影等工具&#xff0c;可以处理出画面的整体明暗…...

通领科技冲刺北交所

高质量增长奔赴产业新征程 日前&#xff0c;通领科技已正式启动在北交所的 IPO 进程&#xff0c;期望借助资本市场的力量&#xff0c;加速技术升级&#xff0c;推动全球化战略布局。这一举措不仅展现了中国汽车零部件企业的强大实力&#xff0c;也预示着行业转型升级的新突破。…...

隐私保护在 Facebook 用户身份验证中的应用

在这个数字化的时代&#xff0c;个人隐私保护成为了公众关注的焦点。社交媒体巨头 Facebook 作为全球最大的社交平台之一&#xff0c;拥有数十亿用户&#xff0c;其在用户身份验证过程中对隐私保护的重视程度直接影响着用户的安全感和信任度。本文将探讨 Facebook 在用户身份验…...

深度学习/强化学习调参技巧

深度调优策略 1. 学习率调整 技巧&#xff1a;学习率是最重要的超参数之一。过大可能导致训练不稳定&#xff0c;过小则收敛速度慢。可以使用学习率衰减&#xff08;Learning Rate Decay&#xff09;或自适应学习率方法&#xff08;如Adam、RMSprop&#xff09;来动态调整学习…...

python面试常见题目

1、python 有几种数据类型 数字:整形 &#xff08;int&#xff09;,浮点型 &#xff08;float&#xff09;布尔 &#xff08; bool&#xff09;:false true字符串 &#xff08;string&#xff09;列表 &#xff08;list&#xff09;元组 &#xff08;tuple&#xff09;字典 &…...

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证书的安装

标题详情作者简介愚公搬代码头衔华为云特约编辑&#xff0c;华为云云享专家&#xff0c;华为开发者专家&#xff0c;华为产品云测专家&#xff0c;CSDN博客专家&#xff0c;CSDN商业化专家&#xff0c;阿里云专家博主&#xff0c;阿里云签约作者&#xff0c;腾讯云优秀博主&…...

manus对比ChatGPT-Deep reaserch进行研究类学术相关数据分析!谁更胜一筹?

没有账号&#xff0c;只能挑选一个案例 一夜之间被这个用全英文介绍全华班出品的新爆款国产AI产品的小胖刷频。白天还没有切换语言的选项&#xff0c;晚上就加上了。简单看了看团队够成&#xff0c;使用很长实践的Monica创始人也在其中。逐渐可以理解&#xff0c;重心放在海外产…...

20250307确认荣品PRO-RK3566开发板在Android13下的以太网络共享功能

20250307确认荣品PRO-RK3566开发板在Android13下的以太网络共享功能 2025/3/7 13:56 缘起&#xff1a;我司地面站需要实现“太网络共享功能”功能。电脑PC要像连接WIFI热点一样连接在Android设备/平板电脑上来实现上网功能/数据传输。 Android设备/平板电脑通过4G/WIFI来上网。…...

Unity Job系统详解原理和基础应用处理大量物体位置

概述 该脚本使用 Unity Job System 和 Burst Compiler 高效管理大量剑对象的位移计算与坐标更新。通过双缓冲技术实现无锁并行计算&#xff0c;适用于需要高性能批量处理Transform的场景。 核心类 SwordManager 成员变量 变量名类型说明swordPrefabGameObject剑对象预制体_d…...

高效编程指南:PyCharm与DeepSeek的完美结合

DeepSeek接入Pycharm 前几天DeepSeek的充值窗口又悄悄的开放了&#xff0c;这也就意味着我们又可以丝滑的使用DeepSeek的API进行各种辅助性工作了。本文我们来聊聊如何在代码编辑器中使用DeepSeek自动生成代码。 注&#xff1a;本文适用于所有的JetBrains开发工具&#xff0c…...

Facebook 的隐私保护数据存储方案研究

Facebook 的隐私保护数据存储方案研究 在这个信息爆炸的时代&#xff0c;数据隐私保护已成为公众关注的热点。Facebook&#xff0c;作为全球最大的社交媒体平台之一&#xff0c;承载着海量用户数据&#xff0c;其隐私保护措施和数据存储方案对于维护用户隐私至关重要。本文将深…...

c#面试题整理

1.如何保持数据库的完整性&#xff0c;一致性 最好的方法&#xff1a;数据库约束&#xff08;check,unique,主键&#xff0c;外键&#xff0c;默认&#xff0c;非空&#xff09; 其次是&#xff1a;用触发器 最后&#xff1a;才是自己些业务逻辑&#xff0c;这个效率低 2.事…...

车载以太网测试-4车载以太网如何进行通信的?

1 摘要 车载以太网的数据传输与接收遵循分层网络架构&#xff08;如OSI模型或TCP/IP模型&#xff09;&#xff0c;从应用层到物理层需要逐层封装与解封装。本文将对车载以太网的数据传输流程进行介绍。 2 以太网通信过程&#xff08;封装与解封装&#xff09; 2.1 发送端流程…...

R软件线性模型与lmer混合效应模型对生态学龙类智力测试数据层级结构应用

全文链接&#xff1a;https://tecdat.cn/?p40925 在生态与生物学研究中&#xff0c;数据常呈现复杂结构特征。例如不同种群、采样点或时间序列的观测数据间往往存在相关性&#xff08;点击文末“阅读原文”获取完整代码、数据、文档&#xff09;。 传统线性模型在处理这类非独…...

WIFI ESP8266以及基础功能介绍

芯片一旦烧写了程序就不可以使用AT指令集&#xff0c;需要重新刷回AT指令库才可以使用 wifi的通信频段是2.4G免费频段。 AT指令 AT&#xff08;attention&#xff09;command set.AT指令集或命令集&#xff0c;一般称为AT指令 海斯命令集&#xff1a;Hayes command set 默认…...

网络六边形受到攻击

大家读完觉得有帮助记得关注和点赞&#xff01;&#xff01;&#xff01; 抽象 现代智能交通系统 &#xff08;ITS&#xff09; 的一个关键要求是能够以安全、可靠和匿名的方式从互联车辆和移动设备收集地理参考数据。Nexagon 协议建立在 IETF 定位器/ID 分离协议 &#xff08;…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

C++:std::is_convertible

C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...

Vue2 第一节_Vue2上手_插值表达式{{}}_访问数据和修改数据_Vue开发者工具

文章目录 1.Vue2上手-如何创建一个Vue实例,进行初始化渲染2. 插值表达式{{}}3. 访问数据和修改数据4. vue响应式5. Vue开发者工具--方便调试 1.Vue2上手-如何创建一个Vue实例,进行初始化渲染 准备容器引包创建Vue实例 new Vue()指定配置项 ->渲染数据 准备一个容器,例如: …...

【决胜公务员考试】求职OMG——见面课测验1

2025最新版&#xff01;&#xff01;&#xff01;6.8截至答题&#xff0c;大家注意呀&#xff01; 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:&#xff08; B &#xff09; A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...

蓝桥杯3498 01串的熵

问题描述 对于一个长度为 23333333的 01 串, 如果其信息熵为 11625907.5798&#xff0c; 且 0 出现次数比 1 少, 那么这个 01 串中 0 出现了多少次? #include<iostream> #include<cmath> using namespace std;int n 23333333;int main() {//枚举 0 出现的次数//因…...

大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计

随着大语言模型&#xff08;LLM&#xff09;参数规模的增长&#xff0c;推理阶段的内存占用和计算复杂度成为核心挑战。传统注意力机制的计算复杂度随序列长度呈二次方增长&#xff0c;而KV缓存的内存消耗可能高达数十GB&#xff08;例如Llama2-7B处理100K token时需50GB内存&a…...

《C++ 模板》

目录 函数模板 类模板 非类型模板参数 模板特化 函数模板特化 类模板的特化 模板&#xff0c;就像一个模具&#xff0c;里面可以将不同类型的材料做成一个形状&#xff0c;其分为函数模板和类模板。 函数模板 函数模板可以简化函数重载的代码。格式&#xff1a;templa…...

智能AI电话机器人系统的识别能力现状与发展水平

一、引言 随着人工智能技术的飞速发展&#xff0c;AI电话机器人系统已经从简单的自动应答工具演变为具备复杂交互能力的智能助手。这类系统结合了语音识别、自然语言处理、情感计算和机器学习等多项前沿技术&#xff0c;在客户服务、营销推广、信息查询等领域发挥着越来越重要…...

无人机侦测与反制技术的进展与应用

国家电网无人机侦测与反制技术的进展与应用 引言 随着无人机&#xff08;无人驾驶飞行器&#xff0c;UAV&#xff09;技术的快速发展&#xff0c;其在商业、娱乐和军事领域的广泛应用带来了新的安全挑战。特别是对于关键基础设施如电力系统&#xff0c;无人机的“黑飞”&…...