正在回答 回答被采纳积分+1
同学你好,sql也没有问题,在数据库中可以查询到数据,如:
建议同学使用queryReceivedUserAwardMapList的sql语句,在数据库中查询一下,查看是否有数据,如:
SELECT uam.user_award_id, uam.create_time, uam.used_status, uam.point, buyer.user_id, buyer.name, s.shop_id, s.shop_name, a.award_id, a.award_name, operator.user_id AS operator_id, operator.name AS operator_name FROM tb_user_award_map uam, tb_person_info buyer, tb_shop s, tb_award a, tb_person_info operator where uam.user_id = buyer.user_id and uam.shop_id = s.shop_id and uam.award_id = a.award_id and uam.operator_id = operator.user_id
祝:学习愉快~
<?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="com.fushan.o2o.dao.UserAwardMapDao">
<resultMap id="userAwardResultMap" type="com.fushan.o2o.entity.UserAwardMap">
<id column="user_award_id" property="userAwardId" />
<result column="create_time" property="createTime" />
<result column="used_status" property="usedStatus" />
<result column="point" property="point" />
<association property="user" column="user_id"
javaType="com.fushan.o2o.entity.PersonInfo">
<id column="user_id" property="userId" />
<result column="name" property="name" />
</association>
<association property="award" column="award_id"
javaType="com.fushan.o2o.entity.Award">
<id column="award_id" property="awardId" />
<result column="award_name" property="awardName" />
</association>
<association property="shop" column="shop_id"
javaType="com.fushan.o2o.entity.Shop">
<id column="shop_id" property="shopId" />
<result column="shop_name" property="shopName" />
</association>
<association property="operator" column="operator_id"
javaType="com.fushan.o2o.entity.PersonInfo">
<id column="operator_id" property="userId" />
<result column="operator_name" property="name" />
</association>
</resultMap>
<select id="queryUserAwardMapList" resultMap="userAwardResultMap">
SELECT
uam.user_award_id,
uam.create_time,
uam.used_status,
uam.point,
buyer.user_id,
buyer.name,
s.shop_id,
s.shop_name,
a.award_id,
a.award_name,
uam.operator_id AS operator_id
FROM
tb_user_award_map uam,
tb_person_info buyer,
tb_shop s,
tb_award a
<where>
uam.user_id = buyer.user_id
and
uam.shop_id = s.shop_id
and
uam.award_id
= a.award_id
<!-- 按顾客信息精确查询 -->
<if
test="userAwardCondition.user!=null
and userAwardCondition.user.userId!=null">
and uam.user_id = #{userAwardCondition.user.userId}
</if>
<!-- 按某个店铺精确查询 -->
<if
test="userAwardCondition.shop!=null
and userAwardCondition.shop.shopId!=null">
and uam.shop_id = #{userAwardCondition.shop.shopId}
</if>
<!-- 按顾客名字模糊查询 -->
<if
test="userAwardCondition.user!=null
and userAwardCondition.user.name!=null">
and buyer.name like
'%${userAwardCondition.user.name}%'
</if>
<!-- 按奖品名模糊查询 -->
<if
test="userAwardCondition.award!=null
and userAwardCondition.award.awardName!=null">
and a.award_name like
'%${userAwardCondition.award.awardName}%'
</if>
<!-- 按奖品可用状态查询 -->
<if test="userAwardCondition.usedStatus!=null">
and uam.used_status = #{userAwardCondition.usedStatus}
</if>
</where>
ORDER BY uam.create_time desc
LIMIT #{rowIndex},#{pageSize};
</select>
<select id="queryReceivedUserAwardMapList" resultMap="userAwardResultMap">
SELECT
uam.user_award_id,
uam.create_time,
uam.used_status,
uam.point,
buyer.user_id,
buyer.name,
s.shop_id,
s.shop_name,
a.award_id,
a.award_name,
operator.user_id AS operator_id,
operator.name AS operator_name
FROM
tb_user_award_map uam,
tb_person_info buyer,
tb_shop s,
tb_award a,
tb_person_info operator
<where>
uam.user_id = buyer.user_id
and
uam.shop_id = s.shop_id
and
uam.award_id
= a.award_id
and
uam.operator_id = operator.user_id
<!-- 按奖品名模糊查询 -->
<if
test="userAwardCondition.award!=null
and userAwardCondition.award.awardName!=null">
and a.award_name like
'%${userAwardCondition.award.awardName}%'
</if>
</where>
ORDER BY uam.create_time desc
LIMIT #{rowIndex},#{pageSize};
</select>
<select id="queryUserAwardMapCount" resultType="int">
SELECT
count(1)
FROM
tb_user_award_map uam,
tb_person_info buyer,
tb_shop
s,
tb_award a
<where>
uam.user_id = buyer.user_id
and
uam.shop_id = s.shop_id
and
uam.award_id
= a.award_id
<!-- 按顾客信息精确查询 -->
<if
test="userAwardCondition.user!=null
and userAwardCondition.user.userId!=null">
and uam.user_id = #{userAwardCondition.user.userId}
</if>
<!-- 按某个店铺精确查询 -->
<if
test="userAwardCondition.shop!=null
and userAwardCondition.shop.shopId!=null">
and uam.shop_id = #{userAwardCondition.shop.shopId}
</if>
<!-- 按顾客名字模糊查询 -->
<if
test="userAwardCondition.user!=null
and userAwardCondition.user.name!=null">
and buyer.name like
'%${userAwardCondition.user.name}%'
</if>
<!-- 按奖品名模糊查询 -->
<if
test="userAwardCondition.award!=null
and userAwardCondition.award.awardName!=null">
and a.award_name like
'%${userAwardCondition.award.awardName}%'
</if>
<!-- 按奖品可用状态查询 -->
<if test="userAwardCondition.usedStatus!=null">
and uam.used_status = #{userAwardCondition.usedStatus}
</if>
</where>
</select>
<select id="queryUserAwardMapById" resultMap="userAwardResultMap">
SELECT
uam.user_award_id,
uam.create_time,
uam.used_status,
uam.point,
buyer.user_id,
buyer.name,
s.shop_id,
s.shop_name,
a.award_id,
a.award_name,
uam.operator_id AS operator_id
FROM
tb_user_award_map uam,
tb_person_info buyer,
tb_shop s,
tb_award a
WHERE
uam.user_id = buyer.user_id
and
uam.shop_id
= s.shop_id
and
uam.award_id
= a.award_id
and
user_award_id =
#{userAwardId}
</select>
<insert id="insertUserAwardMap" parameterType="com.fushan.o2o.entity.UserAwardMap"
useGeneratedKeys="true" keyProperty="userAwardId" keyColumn="user_award_id">
INSERT
INTO
tb_user_award_map(user_id,award_id,shop_id,operator_id,
create_time,used_status,point)
VALUES
(#{user.userId},#{award.awardId},#{shop.shopId},#{operator.userId},
#{createTime},#{usedStatus},#{point})
</insert>
<update id="updateUserAwardMap" parameterType="com.fushan.o2o.entity.UserAwardMap"
useGeneratedKeys="true" keyProperty="userAwardId" keyColumn="user_award_id">
UPDATE
tb_user_award_map
SET
used_status = #{usedStatus},
operator_id=#{operator.userId}
WHERE
user_award_id =
#{userAwardId}
AND user_id = #{user.userId}
</update>
</mapper>
/**
* 列出某个店铺的用户奖品领取情况列表
*
* @param request
* @return
*/
@RequestMapping(value = "/listuserawardmapsbyshop", method = RequestMethod.GET)
@ResponseBody
private Map<String, Object> listUserAwardMapsByShop(HttpServletRequest request) {
Map<String, Object> modelMap = new HashMap<String, Object>();
// 从session里获取店铺信息
Shop currentShop = (Shop) request.getSession().getAttribute("currentShop");
// 获取分页信息
int pageIndex = HttpServletRequestUtil.getInt(request, "pageIndex");
int pageSize = HttpServletRequestUtil.getInt(request, "pageSize");
// 空值判断
if ((pageIndex > -1) && (pageSize > -1) && (currentShop != null) && (currentShop.getShopId() != null)) {
UserAwardMap userAwardMap = new UserAwardMap();
userAwardMap.setShop(currentShop);
// 从请求中获取奖品名
String awardName = HttpServletRequestUtil.getString(request, "awardName");
if (awardName != null) {
// 如果需要按照奖品名称搜索,则添加搜索条件
Award award = new Award();
award.setAwardName(awardName);
userAwardMap.setAward(award);
}
// 分页返回结果
UserAwardMapExecution ue = userAwardMapService.listReceivedUserAwardMap(userAwardMap, pageIndex, pageSize);
modelMap.put("userAwardMapList", ue.getUserAwardMapList());
modelMap.put("count", ue.getCount());
modelMap.put("success", true);
} else {
modelMap.put("success", false);
modelMap.put("errMsg", "empty pageSize or pageIndex or shopId");
}
return modelMap;
}
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星