开发工具:eclipse,jdk1.8
数据库:mysql5.7,Tomcat8.0
package com.softeem.controller;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.softeem.service.GoodsService;
@Controller
public class GoodsController {
@Resource(name="goodsServiceImpl")
GoodsService gservice;
/**
* 查看商品详细信息
* @param id
* @return
*/
@RequestMapping("goods_xiangqing")
@ResponseBody
public ModelAndView xiangqing(String id){
ModelAndView mav=new ModelAndView();
//获取商品id
//System.out.println(id);
//调用业务层的方法
Map<String,Object> map=gservice.goodsinfo(id);
mav.addObject("goods", map);
mav.setViewName("xiangqing");
return mav;
}
/**
* 查询所有商品列表
* @return
*/
@RequestMapping("goods_list")
@ResponseBody
public ModelAndView goodsList(){
ModelAndView mav=new ModelAndView();
//调用服务层,查询所有商品
Map<String,Object> map=gservice.goodsList();
// System.out.println(map.get("status"));
// System.out.println(map.get("msg"));
// System.out.println(map.get("data"));
if("0".equals(map.get("status"))){
//成功
mav.setViewName("list");
mav.addObject("status", "0");
mav.addObject("goodslist", map);
}else{
mav.setViewName("list");
mav.addObject("status", "1");
mav.addObject("goodslist", map);
}
return mav;
}
/**
* 搜索商品(模糊查询)
* @param name
* @return
*/
@RequestMapping("selectGoods")
@ResponseBody
public ModelAndView searchGoods(String name){
ModelAndView mav=new ModelAndView();
//调用业务层模糊查询
Map<String,Object> map=gservice.searchForGoods(name);
mav.setViewName("list");
mav.addObject("goodslist", map);
return mav;
}
}
package com.softeem.controller;
import java.util.HashMap;
import java.util.Map;import javax.annotation.Resource;
import javax.servlet.http.HttpSession;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;import com.softeem.service.AddressService;
@Controller
public class AddressController {
@Resource(name="addressServiceImpl")
AddressService aservice;
/**
* 用户添加收货地址
* @param uid 用户id
* @param adduser 收货人名
* @param phone 收货人手机号
* @param detailadd 详细地址
* @return
*/
@RequestMapping("address_add")
@ResponseBody
public ModelAndView addAddress(String uid,String adduser,String phone,String detailadd,HttpSession session){
ModelAndView mav=new ModelAndView();
//调用业务层
Map<String,Object> map=aservice.addAddress(uid, adduser, phone, detailadd);
session.setAttribute("address", map);
if("2".equals(map.get("status"))){
//达到上限
mav.addObject("code", map.get("status"));
}
mav.setViewName("address");
return mav;
}
/**
* 进入到地址管理界面初始化所有地址信息
* @param uid 用户id
* @return
*/
@RequestMapping("addressAll")
@ResponseBody
public ModelAndView addressAll(String uid){
ModelAndView mav=new ModelAndView();
//调用业务层查询所有地址信息
Map<String,Object> map=aservice.addressAll(uid);
mav.setViewName("address");
mav.addObject("address", map);
return mav;
}
/**
* 修改默认地址的方法
* @param id 地址id
* @param uid 用户id
* @return
*/
@RequestMapping("address_changeDefault")
@ResponseBody
public Map<String,Object> modifyDefaultAddress(String id,String uid){
//调用业务层修改状态
Map<String,Object> map=aservice.modifyDefaultAddress(id, uid);
return map;
}
/**
* 删除地址
* @param id 地址id
* @param uid 用户id
* @return
*/
@RequestMapping("address_del")
@ResponseBody
public Map<String,Object> delAddress(String id,String uid){
//调用业务层
//addressAll(uid);
return aservice.delAddress(id, uid);
}
}
源码获取:关注底部gongzhonghao,024领取下载链接