content
1. MyBatisX plugin installation
2. MyBatisX code is quickly generated
3. MyBatisPlusX quickly generates CRUD
MyBatis-Plus provides us with powerful mapper and service templates, which can greatly improve development efficiency
But in the real development process, MyBatis-Plus cannot solve all problems for us, such as some complex SQL, multi-table join query, we need to write code and SQL statements ourselves, how can we quickly solve this problem? At this time, you can use the MyBatisX plugin
Official website description: MyBatisX is an IDEA-based rapid development plug-in, born for efficiency.
Official Documentation: MybatisX Rapid Development Plugin | MyBatis-Plus
1. MyBatisX plugin installation
2. MyBatisX code is quickly generated
① After connecting to the database, select the table corresponding to the code to be generated
② Modify as needed
3. MyBatisPlusX quickly generates CRUD
3.1, add
As shown in the figure below, after entering insertSelective, alt + Enter to select the second option, and the SQL statement will be automatically generated in UserMapper.xml
The generated SQL statement is as follows
<insert id="insertSelective">
insert into t_user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">uid,</if>
<if test="userName != null">user_name,</if>
<if test="age != null">age,</if>
<if test="email != null">email,</if>
<if test="sex != null">sex,</if>
<if test="isDeleted != null">is_deleted,</if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="uid != null">#{uid,jdbcType=BIGINT},</if>
<if test="userName != null">#{userName,jdbcType=VARCHAR},</if>
<if test="age != null">#{age,jdbcType=INTEGER},</if>
<if test="email != null">#{email,jdbcType=VARCHAR},</if>
<if test="sex != null">#{sex,jdbcType=INTEGER},</if>
<if test="isDeleted != null">#{isDeleted,jdbcType=INTEGER},</if>
</trim>
</insert>
3.2, delete
After entering deleteBy, IDEA auto-completion will automatically prompt the fields of the table
If you need to delete based on multiple conditions, you can continue to enter and
After inputting, alt + Enter, select the option below
Generated SQL:
<delete id="deleteByUidAndUserName">
delete
from t_user
where uid = #{uid,jdbcType=NUMERIC}
AND user_name = #{userName,jdbcType=VARCHAR}
</delete>
3.3. Modification
Generated SQL:
<update id="updateAgeAndSexByUid">
update t_user
set age = #{age,jdbcType=NUMERIC},
sex = #{sex,jdbcType=NUMERIC}
where uid = #{uid,jdbcType=NUMERIC}
</update>
3.4. Query
Generated SQL:
<select id="selectAgeAndSexByAgeBetween" resultMap="BaseResultMap">
select age, sex
from t_user
where age between #{beginAge,jdbcType=INTEGER} and #{endAge,jdbcType=INTEGER}
</select>
3.5. Sorting query results
<select id="selectAllOrderByAgeDesc" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user
order by age desc
</select>