导入依赖:
配置文件
鉴别器:
如果查出是女生:就把部门信息查询出来,否则不查询;如果是男 生,把last_name这一列的值赋值给email;
<resultMap id="MyEmpDis" type="com.example.demo.entity.Dept">
<id column="id" property="deptId"/>
<result column="username" property="orderNum"/>
<result column="password" property="parentId"/>
<discriminator javaType="string" column="username">
<!--如果是女生,-->
<case value="0" resultType="employee">
<association property="deptId" select="com.example.demo.mapper.UserMapper.selectByPrimaryKeyWithDept3" column="dept_id">
</association>
</case>
<!--如果是男生-->
<case value="1" resultType="employee">
<id column="id" property="deptId"/>
<result column="" property=" "/>
<result column="" property=" "/>
</case>
</discriminator>
</resultMap>
调用存储器:
#建表插值
create table user(
id int primary key auto_increment,
name varchar(10),
sex char(2))ENGINE=InnoDB default charset=utf8;
insert into user(name,sex) values('A',"男");
#建存储过程
create procedure count(IN sex_ud INT,OUT user_count INT)
begin
if sex_id=0 then
select count(*) from user where user.sex ='女' INTO user_count;
else
select count(*) from user where user.sex='男' INTO user_count;
end if;
end
#调用存储过程
set @user_count = 0;
call count(1,@user_count);
select @user_count;
查询得到男生女生的数量mapper.xml
查询