JavaEE复习

1、根据以下表字段与类属性的对应关系,在Mybatis配置文件中定义get方法,该方法可根据主键card_id 获取card_info表数据,表对应的类的别名为CardPOJO。请给出定义的和。
在这里插入图片描述

<resultMap id = "cardResultMap" type = "CardPOJO">
    <id property = "cardId" columm = "card_id">
    <result property = "balance" column = "balance">
</resultMap>

<select id = "get" resultMap = "cardResultMap">
    select * from card_info where card_id = #{cardId}
</select>

2、请根据以下POJO 类的属性写出对应的BlogPOJO对应的ResultMap ,POIO类变量对应表字段名一致,BlogPOJO类的别名为BlogPOJO。
在这里插入图片描述

<resultMap id = "blogResultMap" type = "BlogPOJO">
    <id property = "id" column = "id">
    <result property = "title" column = "title">
    <association property = "authorPOJO" javaType = "AuthorPOJO">
        <id property = "authorId" column = "authorId">
        <result property = "name" column = "name">
    </association>
</resultMap>

3、请根据以下POJO类的属性写出对应的AuthorPOJO对应的ResultMap,POJO类的变量与表的字段名一致
在这里插入图片描述

<resultMap id = "authorResultMap" type = "AuthorPOJO">
	<id property = "id" column = "id">
	<result property = "name" column = "name">
	<collection property = "blogList" javaType = "ArrayList" ofType = "BlogPOJO">
		<id property = "blogId" column = "blogId">
		<result property = "title" column = "title">
	</collection>
</resultMap>

4、当major不为空时,执行select *from student where major= ?;当name不为空时,执行select * from student where name = ?;以上两个条件不满足则执行select *from student where class = ?。请使用Mybatis的动态SQL实现以上功能。注意:该SQL语句对应的方法名为get,返回数据类型的别名为StudentPOJO。

<select id = "get" resultType = "StudentPOJO">
	select * from student where 
	<choose>
		<when test = "major!=null and major!=''"> major=#{major} </when>
		<when test = "name!=null and name!=''"> name = #{name} </when>
		<otherwise> class = #{class} </otherwise>
	</choose>
</select> 

5、DAO接口存在方法List getByIds(List ids),请使用Mybatis的动态语言返回user表中id存在于参数列表中的记录,注意,数据库表的字段与POJO类的字段名一致,POJO类的别名为User。

<select id = "getByIds" resultType = "User">
	select * from user where id in
	<foreach collection = "list" item = "id" index = "index" separator = "," open = "(" close = ")">
		#{id}
	</foreach>
</select>

6、如果major,name,class不为空,则根据id更新对应数据。请使用Mybatis使用以上功能。注意DAO接口对应的方法为void update(Student student),Mybatis定义POJO类Student的别名为Student,数据库表student的字段与POJO类的字段名一致。

<update id = "update">
	update student
	<set>
		<if test = "major!=null and major!=''">major=#{major},</if>
		<if test = "name!=null and name!=''">name=#{name},</if>
		<if test = "class!=null and class!=''">class=#{class},</if>
	</set>
	where id = #{id}
</update>

7、使用动态SQL实现goods表的查询,接口方法为
ListgetList(HashMap<String, Object> map),
map 中键的取值范围为minPrice,maxPrice和desc,筛选条件如下:
(1)当desc 的值不为空时,根据其值做模糊匹配
(2)当minPrice或maxPrice不为空时,根据其中做price范围限定
(3)当以上条件都不满足时,检索整张表的记录。
GoodsPOJO类的别名为GoodsPOJO,表的字段与POJO类的属性命名一致。

<select id = "getList" resultType = "GoodsPOJO">
	select * from goods
	<where>
		<if test = "desc!=null and desc!=''"> desc like #{desc} </if>
		<if test = "minPrice!=null and minPrice!=''"> and price &gt;=#{minPrice} </if>
		<if test = "maxPrice!=null and maxPrice!=''"> and price &lt;=#{maxPrice} </if>
	</where>
	where id = #{id}
</select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值