DELIMITER // DROP PROCEDURE IF EXISTS dowhile // CREATE PROCEDURE dowhile() BEGIN DECLARE age INT DEFAULT 25; DECLARE i INT DEFAULT 1; DECLARE teacherId INT DEFAULT 1; DECLARE gender CHAR(1) charset 'utf8'; WHILE i<=500000 DO SET age = FLOOR(20+RAND()*15); SET teacherId = ROUND(RAND()) + 1; SET gender = SUBSTRING("男女",FLOOR(1+2*RAND()),1); INSERT INTO USER(id,name,age,email,gender,createTime,loginTime,teacherId) VALUES (i,CONCAT('user',i),age,'user@126.com',gender,current_timestamp(),current_timestamp(),teacherId); SET i=i+1; END WHILE; END; //
call dowhile();
修改完数据库之后,要修改一下测试类里面的断言判断,改成user1
assertTrue(user.getName().equals("student1"));
HTTP GET 请求/users 返回users列表 HTTP GET 请求/users/1 返回id=1的user信息 HTTP POST 请求/users 带着一个user对象JSON格式创建一个新的user HTTP PUT 请求/users/1 带着一个user对象JSON格式更新id=1的user信息 HTTP DELETE 请求/users/1 删除id=1的user
<resultMap id="BaseResultMapRename" type="com.study.model.User"> <id column="uId" jdbcType="BIGINT" property="id" /> <result column="uName" jdbcType="VARCHAR" property="name" /> <result column="uAge" jdbcType="INTEGER" property="age" /> <result column="uEmail" jdbcType="VARCHAR" property="email" /> <result column="uCreateTime" jdbcType="TIMESTAMP" property="createTime" /> <result column="uLoginTime" jdbcType="TIMESTAMP" property="loginTime" /> <result column="uTeacherId" jdbcType="BIGINT" property="teacherId" /> <result column="uGender" jdbcType="VARCHAR" property="gender" /> </resultMap> <sql id="Base_Column_ListRename"> u.id as uId, u.name as uName, u.age as uAge, u.email as uEmail, u.createTime as uCreateTime, u.loginTime as uLoginTime, u.teacherId as uTeacherId, u.gender as uGender </sql>
<select id="selectUsers" resultMap="UnionResultMap"> select <include refid="Base_Column_ListRename" /> , <include refid="com.study.dao.TeacherMapper.Base_Column_ListRename" /> from user u, teacher t where u.teacherId = t.id order by u.id </select> <resultMap id="UnionResultMap" type="com.study.model.User" extends="BaseResultMapRename"> <association property="teacher" column="teacherId" javaType="com.study.model.Teacher" resultMap="com.study.dao.TeacherMapper.BaseResultMapRename"> </association> </resultMap> <select id="selectUsersPaginition" parameterType="HashMap" resultMap="UnionResultMap"> select <include refid="Base_Column_ListRename" /> , <include refid="com.study.dao.TeacherMapper.Base_Column_ListRename" /> from user u, teacher t where u.teacherId = t.id order by u.id limit #{offset},#{pagesize} </select> <select id="getCount" resultType="long"> select count(*) from user </select>
teacherMapper.xml里面添加
<resultMap id="BaseResultMapRename" type="com.study.model.Teacher"> <id column="tId" jdbcType="BIGINT" property="id" /> <result column="tName" jdbcType="VARCHAR" property="name" /> <result column="tAge" jdbcType="INTEGER" property="age" /> <result column="tGender" jdbcType="VARCHAR" property="gender" /> <result column="tCreateTime" jdbcType="TIMESTAMP" property="createTime" /> <result column="tLoginTime" jdbcType="TIMESTAMP" property="loginTime" /> <result column="tEmail" jdbcType="VARCHAR" property="email" /> </resultMap> <sql id="Base_Column_ListRename"> t.id as tId, t.name as tName, t.age as tAge, t.gender as tGender, t.createTime as tCreateTime, t.loginTime as tLoginTime, t.email as tEmail </sql>