当前位置: 首页 > 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 默认…...

变量 varablie 声明- Rust 变量 let mut 声明与 C/C++ 变量声明对比分析

一、变量声明设计&#xff1a;let 与 mut 的哲学解析 Rust 采用 let 声明变量并通过 mut 显式标记可变性&#xff0c;这种设计体现了语言的核心哲学。以下是深度解析&#xff1a; 1.1 设计理念剖析 安全优先原则&#xff1a;默认不可变强制开发者明确声明意图 let x 5; …...

【JavaEE】-- HTTP

1. HTTP是什么&#xff1f; HTTP&#xff08;全称为"超文本传输协议"&#xff09;是一种应用非常广泛的应用层协议&#xff0c;HTTP是基于TCP协议的一种应用层协议。 应用层协议&#xff1a;是计算机网络协议栈中最高层的协议&#xff0c;它定义了运行在不同主机上…...

python/java环境配置

环境变量放一起 python&#xff1a; 1.首先下载Python Python下载地址&#xff1a;Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个&#xff0c;然后自定义&#xff0c;全选 可以把前4个选上 3.环境配置 1&#xff09;搜高级系统设置 2…...

HTML 列表、表格、表单

1 列表标签 作用&#xff1a;布局内容排列整齐的区域 列表分类&#xff1a;无序列表、有序列表、定义列表。 例如&#xff1a; 1.1 无序列表 标签&#xff1a;ul 嵌套 li&#xff0c;ul是无序列表&#xff0c;li是列表条目。 注意事项&#xff1a; ul 标签里面只能包裹 li…...

React Native在HarmonyOS 5.0阅读类应用开发中的实践

一、技术选型背景 随着HarmonyOS 5.0对Web兼容层的增强&#xff0c;React Native作为跨平台框架可通过重新编译ArkTS组件实现85%以上的代码复用率。阅读类应用具有UI复杂度低、数据流清晰的特点。 二、核心实现方案 1. 环境配置 &#xff08;1&#xff09;使用React Native…...

Python实现prophet 理论及参数优化

文章目录 Prophet理论及模型参数介绍Python代码完整实现prophet 添加外部数据进行模型优化 之前初步学习prophet的时候&#xff0c;写过一篇简单实现&#xff0c;后期随着对该模型的深入研究&#xff0c;本次记录涉及到prophet 的公式以及参数调优&#xff0c;从公式可以更直观…...

如何在看板中有效管理突发紧急任务

在看板中有效管理突发紧急任务需要&#xff1a;设立专门的紧急任务通道、重新调整任务优先级、保持适度的WIP&#xff08;Work-in-Progress&#xff09;弹性、优化任务处理流程、提高团队应对突发情况的敏捷性。其中&#xff0c;设立专门的紧急任务通道尤为重要&#xff0c;这能…...

ETLCloud可能遇到的问题有哪些?常见坑位解析

数据集成平台ETLCloud&#xff0c;主要用于支持数据的抽取&#xff08;Extract&#xff09;、转换&#xff08;Transform&#xff09;和加载&#xff08;Load&#xff09;过程。提供了一个简洁直观的界面&#xff0c;以便用户可以在不同的数据源之间轻松地进行数据迁移和转换。…...

Java线上CPU飙高问题排查全指南

一、引言 在Java应用的线上运行环境中&#xff0c;CPU飙高是一个常见且棘手的性能问题。当系统出现CPU飙高时&#xff0c;通常会导致应用响应缓慢&#xff0c;甚至服务不可用&#xff0c;严重影响用户体验和业务运行。因此&#xff0c;掌握一套科学有效的CPU飙高问题排查方法&…...

AI病理诊断七剑下天山,医疗未来触手可及

一、病理诊断困局&#xff1a;刀尖上的医学艺术 1.1 金标准背后的隐痛 病理诊断被誉为"诊断的诊断"&#xff0c;医生需通过显微镜观察组织切片&#xff0c;在细胞迷宫中捕捉癌变信号。某省病理质控报告显示&#xff0c;基层医院误诊率达12%-15%&#xff0c;专家会诊…...