"t_student" domainObjectName="Student" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 此时会报错,如下
这个时候可以不用理会,项目也是会正常运行的,当然也可以这样:
添加之后就不会报红了。
Spring Boot 理论+实战系列 教程大家看这个:
https://github.com/javastacks/spring-boot-best-practice
3. 在pom.xml 文件中添加 mysql 反向工程依赖 org.mybatis.generator mybatis-generator-maven-plugin 1.3.6 GeneratorMapper.xml true true
4. 双击生成相关文件 5. 生成的文件自动生成model/Student、实体类
以及StudentMapper,接口
StudentMapper.xml 具体对数据库的操作
这样方便我们使用,具体的下面详细介绍,注意看注释
Student
package com.md.springboot.model; public class Student { private Integer id; private String name; private Integer age; public Integer getId () { return id; } public void setId(Integer id) { this.id = id; } public String getName () { return name; } public void setName(String name) { this.name = name; } public Integer getAge () { return age; } public void setAge(Integer age) { this.age = age; } }
StudentMapper
package com.md.springboot.mapper; import com.md.springboot.model.Student; public interface StudentMapper { int deleteByPrimaryKey(Integer id); int insert(Student record); int insertSelective(Student record); Student selectByPrimaryKey(Integer id); int updateByPrimaryKeySelective(Student record); int updateByPrimaryKey(Student record); }
StudentMapper.xml
"1.0" encoding="UTF-8" ?> "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > "com.md.springboot.mapper.StudentMapper"> "BaseResultMap" type ="com.md.springboot.model.Student" > "id" jdbcType="INTEGER" property="id" /> "name" jdbcType="VARCHAR" property="name" /> "age" jdbcType="INTEGER" property="age" /> "Base_Column_List"> id, name, age "selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap" > select "Base_Column_List" /> from t_student where id = #{id,jdbcType=INTEGER} "deleteByPrimaryKey" parameterType="java.lang.Integer" > delete from t_student where id = #{id,jdbcType=INTEGER} "insert" parameterType="com.md.springboot.model.Student" > insert into t_student (id, name, age ) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER} ) "insertSelective" parameterType="com.md.springboot.model.Student" > insert into t_student "(" suffix=")" suffixOverrides="," > <if test ="id != null" > id, if > <if test ="name != null" > name, if > <if test ="age != null" > age, if > "values (" suffix=")" suffixOverrides="," > <if test ="id != null" > #{id,jdbcType=INTEGER}, if > <if test ="name != null" > #{name,jdbcType=VARCHAR}, if > <if test ="age != null" > #{age,jdbcType=INTEGER}, if > "updateByPrimaryKeySelective" parameterType="com.md.springboot.model.Student" > update t_student <set > <if test ="name != null" > name = #{name,jdbcType=VARCHAR}, if > <if test ="age != null" > age = #{age,jdbcType=INTEGER}, if > set > where id = #{id,jdbcType=INTEGER} "updateByPrimaryKey" parameterType="com.md.springboot.model.Student" > update t_student set name = #{name,jdbcType=VARCHAR}, age = #{age,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}
关注微信公众号:Java技术栈,在后台回复:Mybatis,可以获取我整理的 N 篇 Mybatis 教程,都是干货。 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本文链接:https://blog.csdn.net/m0_37922192/article/details/109248865
浏览
34 点赞
评论
收藏
分享
手机扫一扫分享
分享
举报
点赞
评论
收藏
分享
手机扫一扫分享
分享
举报