1.环境介绍
eclipse。InteIIij idea用户也可参照,简单明了。
springboot 2.1.8
mybatis持久层
mysql数据库
2.新建springboot项目
图片中的依赖分别是
springboot DevTools 热部署依赖
MySQL Driver mysql依赖
mybatis mybatis持久层框架
springweb spring reactive web web访问依赖
3.建包,采用mvc模式
tgc.edu.zz下面的包就不做解释了,
其中mapper包是装mybatis.xml书写sql语句的
4.在mapper中新建userEntityMapper.xml文件,将基本sql语句写入, 并且映射好他对应的实体类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="tgc.edu.zz.dao.UserDao">
<!-- 查询所有 -->
<select id="findAll" resultType="tgc.edu.zz.entity.UserEntity">
select * from user_entity
</select>
<!--根据id查询-->
<select id="findById" resultType="tgc.edu.zz.entity.UserEntity" parameterType="java.lang.Integer">
select * from user_entity where id = #{id}
</select>
<!--按照姓名模糊查询-->
<select id="findByName" resultTy