功能介绍
注册用户:收藏管理、订单管理、地址管理、安全管理、购物车管理
管理员:商品管理、订单管理、用户管理、轮播图管理、评论管理、商品分类管理、账户管理
部分功能模块代码
package com.phonemarket.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.phonemarket.entity.Address;
import com.phonemarket.entity.Areas;
import com.phonemarket.entity.Cities;
import com.phonemarket.entity.Provinces;
import com.phonemarket.entity.Users;
import com.phonemarket.service.IAddressService;
import com.phonemarket.service.IProCityAreaService;
/**
* @author 张贤
*
*/
@Controller
@RequestMapping("/address")
public class AddressController {
@Autowired
private IAddressService addressService;
@Autowired
private IProCityAreaService pService;
@RequestMapping("findAddrByUserId")
@ResponseBody
public List<Address> findAddrByUserId(HttpServletRequest request) {
HttpSession session = request.getSession();
Users user = (Users) session.getAttribute("user");
List<Address> list = addressService.findAddressByUserId(user.getUserId());
return list;
}
@RequestMapping("addAddress")
@ResponseBody
public String addAddress(Address addr,HttpServletRequest request) {
String provinceId = addr.getAddrProvince();
String cityId = addr.getAddrCity();
String areaId = addr.getAddrArea();
Provinces province = pService.findProvinceById(provinceId);
Cities city = pService.findCityById(cityId);
Areas area = pService.findAreaById(areaId);
addr.setAddrProvince(province.getProvinceName());
addr.setAddrCity(city.getCityName());
addr.setAddrArea(area.getAreaName());
HttpSession session = request.getSession();
Users user = (Users) session.getAttribute("user");
addr.setAddrUser(user.getUserId());
Integer rs = addressService.addAddress(addr);
if(rs>0){
return "success";
}else{
return "fail";
}
}
@RequestMapping("findAddressById")
@ResponseBody
public Address findAddrByAddrId(Integer addrId){
Address addr = addressService.findAddresById(addrId);
Provinces province = pService.findProvinceByName(addr.getAddrProvince());
Cities city = pService.findCityByName(addr.getAddrCity(),province.getProvinceId());
Areas area = pService.findAreaByName(addr.getAddrArea(),city.getCityId());
addr.setAddrProvince(province.getProvinceId());
addr.setAddrCity(city.getCityId());
addr.setAddrArea(area.getAreaId());
return addr;
}
@RequestMapping("modifyAddress")
@ResponseBody
public String modifyAddress(Address addr){
String provinceId = addr.getAddrProvince();
String cityId = addr.getAddrCity();
String areaId = addr.getAddrArea();
Provinces province = pService.findProvinceById(provinceId);
Cities city = pService.findCityById(cityId);
Areas area = pService.findAreaById(areaId);
addr.setAddrProvince(province.getProvinceName());
addr.setAddrCity(city.getCityName());
addr.setAddrArea(area.getAreaName());
Integer rs = addressService.updateAddress(addr);
if(rs>0){
return "success";
}else{
return "fail";
}
}
@RequestMapping("deleteAddress")
@ResponseBody
public String deleteAddress(Integer addrId){
Integer rs = addressService.deleteAddress(addrId);
if(rs>0){
return "success";
}else{
return "fail";
}
}
}
package com.phonemarket.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.phonemarket.entity.Address;
import com.phonemarket.entity.Areas;
import com.phonemarket.entity.Cities;
import com.phonemarket.entity.Provinces;
import com.phonemarket.mapper.AddressMapper;
import com.phonemarket.mapper.AreasMapper;
import com.phonemarket.mapper.CitiesMapper;
import com.phonemarket.mapper.ProvincesMapper;
import com.phonemarket.service.IAddressService;
/**
* @author 张贤
*
*/
@Service
public class AddressServiceImpl implements IAddressService {
@Autowired
private AddressMapper addressMapper;
@Autowired
private ProvincesMapper proMapper;
@Autowired
private CitiesMapper cityMapper;
@Autowired
private AreasMapper areaMapper;
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
@Override
public List<Address> findAddressByUserId(Integer userId) {
return addressMapper.findAddrByUserId(userId);
}
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
@Override
public Address findAddresById(Integer id) {
return addressMapper.findAddrById(id);
}
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
@Override
public Provinces findProByProByName(String name) {
return proMapper.findProByProName(name);
}
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
@Override
public Cities findCityByCityName(String name,String provinceId) {
return cityMapper.findCityByCityName(name,provinceId);
}
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
@Override
public Areas findAreaByAreaName(String name,String cityId) {
return areaMapper.findAreaByAreaName(name,cityId);
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
@Override
public Integer addAddress(Address addr) {
return addressMapper.addAddress(addr);
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
@Override
public Integer updateAddress(Address addr) {
return addressMapper.updateAddr(addr);
}
@Transactional(propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
@Override
public Integer deleteAddress(Integer addrId) {
return addressMapper.deleteAddr(addrId);
}
}
论文目录