目录
寻主
内容介绍
1. 入库宠物-上架 (掌握)
2. 宠物前台展示 (掌握)
3. 领养/售卖 (掌握)
1.宠物管理模块
类型管理:扩展功能
宠物管理:
有crud,还有上架于下架,和服务差不多。 前后台都拷贝服务模块的。
2.宠物前台展示
2.1.宠物列表
Copy product.html
2.2.宠物详情
2.2.1.跳转到店铺
1)拷贝主页为店铺页
2)跳转到店铺页 宠物详情页
3)美化店铺
<script type="text/javascript">
new Vue({
el:"#myDiv",
data:{
user:{},
shopId:null,
shop:{}
},
methods:{
goPublish(){
window.open("publish.html");
},
getShop(){
this.$http.get("/shop/"+this.shopId)
.then(result=>{
this.shop = result.data;
document.getElementById("myTitle").innerHTML = this.shop.name;
});
}
},
mounted(){
let user = localStorage.getItem("uUser");
if(user){
this.user = JSON.parse(user);
}
this.shopId = parseUrlParams2Obj(location.href).id;
this.getShop();
}
})
</script>
2.2.2.领养
1)前台
adopt(){
let petId = this.pet.id;
let flag = window.confirm("你确认包养吗?")
if(flag){
this.$http.get("/pet/adopt/"+petId)
.then(result=>{
result = result.data;
if(result.success){
alert("领养成功!")
location.href = "personcenter.html"
}else{
alert(result.message);
}
})
}
}
}
2)后台
Controller
@GetMapping("/adopt/{id}")
public AjaxResult adopt(@PathVariable(value = "id")Long petId, HttpServletRequest request){
LoginInfo loginInfo = LoginContext.getLoginInfo(request);
try {
petService.adopt(petId,loginInfo.getId());
return AjaxResult.me();
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.me().setSuccess(false).setMessage("不允许包养!"+e.getMessage());
}
}
Service
@Override
public void adopt(Long petId,Long loginInfoId) {
Pet pet = petMapper.loadById(petId);
System.out.println(pet);
//1 绑定领养用户
User user = userMapper.loadByLoginInfoId(loginInfoId);
pet.setUser_id(user.getId());
//2 修改状态
pet.setState(2); //已领养
petMapper.update(pet);
//3 @TODO 创建领养订单
}
Mapper.xml
<update id="update" parameterType="Pet">
update t_pet set
name = #{name},
resources= #{resources},
saleprice= #{saleprice},
offsaletime= #{offsaletime},
onsaletime= #{onsaletime},
state= #{state},
costprice= #{costprice},
createtime= #{createtime},
type_id= #{type_id},
shop_id= #{shop_id},
user_id= #{user_id},
search_master_msg_id= #{searchMasterMsg_id}
where id = #{id}
</update>
<resultMap id="petMap" type="Pet">
<id property="id" column="id"></id>
<result property="name" column="name"></result>
<result property="resources" column="resources"></result>
<result property="saleprice" column="saleprice"></result>
<result property="costprice" column="costprice"></result>
<result property="offsaletime" column="offsaletime"></result>
<result property="onsaletime" column="onsaletime"></result>
<result property="state" column="state"></result>
<result property="createtime" column="createtime"></result>
<result property="searchMasterMsg_id" column="search_master_msg_id"></result>
<result property="type_id" column="type_id"></result>
<result property="shop_id" column="shop_id"></result>
<!--private PetDetail detail = new PetDetail();-->
<association property="detail" javaType="PetDetail">
<id property="id" column="pdid"></id>
<result property="intro" column="intro"></result>
<result property="adoptNotice" column="adoptNotice"></result>
</association>
<association property="shop" javaType="Shop">
<id property="id" column="sid"></id>
<result property="name" column="sname"></result>
</association>
</resultMap>
2.3.扩展功能
1)宠物类型
2)查询自己宠物
后台通过当前登录用户id,查询宠物在用户中心,我的资产里面,我的宠物进行展示
拷贝客人个人中心页面
3.
4.
5.课程总结
宠物后台管理
宠物前台列表
宠物详情页面
基本展示
跳转到店铺页面
包养
查看用户自己宠物
锻炼找错能力