基于javaweb+mysql的ssm+maven校园二手交易平台(java+ssm+thymeleaf+html+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven校园二手交易平台(java+ssm+thymeleaf+html+jquery+mysql)
项目介绍
本次设计的是一个校园二手交易平台(C2C),C2C指个人与个人之间的电子商务,买家可以查看所有卖家发布的商品,并且根据分类进行商品过滤,也可以根据站内搜索引擎进行商品的查询,并且与卖家联系,达成交易的意向,也可以发布求购的信息,让卖家查看之后,与之联系,进行交易。而此次主要是针对校园用户所设计的网站,对于数据的分类应该更多的考虑校园用户的需求,例如二手书籍、二手数码等的分类应该更加细致。由于是C2C的项目,因此本项目无需后台管理。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 5.7版本;
技术栈
- 后端:Spring SpringMVC MyBatis 2. 前端:Thymeleaf+Html+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/xxx 登录
public String login(HttpServletRequest request, Model model) {
String token = TokenProccessor.getInstance().makeToken();
log.info("进入登录界面,token为:" + token);
request.getSession().setAttribute("token", token);
model.addAttribute("token", token);
return "page/login_page";
}
//退出
@RequestMapping(value = "/logout.do")
public String logout(HttpServletRequest request) {
try {
request.getSession().removeAttribute("userInformation");
request.getSession().removeAttribute("uid");
System.out.println("logout");
} catch (Exception e) {
e.printStackTrace();
return "redirect:/home.do";
}
return "redirect:/";
}
//用户注册,拥有插入数据而已,没什么用的
@RequestMapping(value = "/registered.do", method = RequestMethod.POST)
public String registered(Model model,
@RequestParam String name, @RequestParam String phone, @RequestParam String password) {
UserInformation userInformation = new UserInformation();
userInformation.setUsername(name);
userInformation.setPhone(phone);
userInformation.setModified(new Date());
userInformation.setCreatetime(new Date());
if (userInformationService.insertSelective(userInformation) == 1) {
int uid = userInformationService.selectIdByPhone(phone);
UserPassword userPassword = new UserPassword();
userPassword.setModified(new Date());
password = StringUtils.getInstance().getMD5(password);
userPassword.setPassword(password);
userPassword.setUid(uid);
int result = userPasswordService.insertSelective(userPassword);
if (result != 1) {
model.addAttribute("result", "fail");
return "success";
}
model.addAttribute("result", "success");
return "success";
}
model.addAttribute("result", "fail");
return "success";
}
//用户注册
userName = StringUtils.getInstance().replaceBlank(userName);
userInformation.setUsername(userName);
} else if (userName != null && userName.length() >= 25) {
return map;
}
if (realName != null && realName.length() < 25) {
realName = StringUtils.getInstance().replaceBlank(realName);
userInformation.setRealname(realName);
} else if (realName != null && realName.length() >= 25) {
return map;
}
if (clazz != null && clazz.length() < 25) {
clazz = StringUtils.getInstance().replaceBlank(clazz);
userInformation.setClazz(clazz);
} else if (clazz != null && clazz.length() >= 25) {
return map;
}
if (sno != null && sno.length() < 25) {
sno = StringUtils.getInstance().replaceBlank(sno);
userInformation.setSno(sno);
} else if (sno != null && sno.length() >= 25) {
return map;
}
if (dormitory != null && dormitory.length() < 25) {
dormitory = StringUtils.getInstance().replaceBlank(dormitory);
userInformation.setDormitory(dormitory);
} else if (dormitory != null && dormitory.length() >= 25) {
return map;
}
if (gender != null && gender.length() <= 2) {
gender = StringUtils.getInstance().replaceBlank(gender);
userInformation.setGender(gender);
} else if (gender != null && gender.length() > 2) {
return map;
}
int result = userInformationService.updateByPrimaryKeySelective(userInformation);
if (result != 1) {
//更新失败,认证失败
return map;
}
//认证成功
request.getSession().setAttribute("userInformation", userInformation);
map.put("result", 1);
return map;
}
//enter the publishUserWant.do.html,进入求购页面
@RequestMapping(value = "/require_product.do")
public String enterPublishUserWant(HttpServletRequest request, Model model) {
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return "redirect:/login.do";
}
String error = request.getParameter("error");
// remark = StringUtils.replaceBlank(remark);
// name = StringUtils.getInstance().txtReplace(name);
// remark = StringUtils.getInstance().txtReplace(remark);
try {
if (name.length() < 1 || remark.length() < 1 || name.length() > 25 || remark.length() > 25) {
return "redirect:require_product.do";
}
} catch (Exception e) {
e.printStackTrace();
return "redirect:require_product.do?error=1";
}
UserWant userWant = new UserWant();
userWant.setModified(new Date());
userWant.setName(name);
userWant.setPrice(new BigDecimal(price));
userWant.setQuantity(quantity);
userWant.setRemark(remark);
userWant.setUid((Integer) request.getSession().getAttribute("uid"));
userWant.setSort(sort);
int result;
try {
result = userWantService.insertSelective(userWant);
if (result != 1) {
// map.put("result", result);
return "redirect:/require_product.do?error=2";
}
} catch (Exception e) {
e.printStackTrace();
// map.put("result", result);
return "redirect:/require_product.do?error=2";
}
// map.put("result", result);
return "redirect:/my_require_product.do";
}
//getUserWant,查看我的求购
@RequestMapping(value = {"/my_require_product.do", "/my_require_product_page.do"})
public String getUserWant(HttpServletRequest request, Model model) {
List<UserWant> list;
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return "redirect:/login.do";
}
try {
int uid = (int) request.getSession().getAttribute("uid");
// list = selectUserWantByUid(4);
list = selectUserWantByUid(uid);
List<UserWantBean> userWantBeans = new ArrayList<>();
for (UserWant userWant : list) {
UserWantBean userWantBean = new UserWantBean();
map.put("counts", -1);
return map;
}
int counts = getReleaseCounts((Integer) request.getSession().getAttribute("uid"));
map.put("counts", counts);
return map;
}
//查看我的发布的商品
@RequestMapping(value = "/my_publish_product_page.do")
public String getReleaseShop(HttpServletRequest request, Model model) {
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return "redirect:/login.do";
} else {
model.addAttribute("userInformation", userInformation);
}
int uid = (int) request.getSession().getAttribute("uid");
List<ShopInformation> shopInformations = shopInformationService.selectUserReleaseByUid(uid);
List<ShopInformationBean> list = new ArrayList<>();
String stringBuffer;
// int i=0;
for (ShopInformation shopInformation : shopInformations) {
// if (i>=5){
// break;
// }
// i++;
stringBuffer = getSort(shopInformation.getSort());
ShopInformationBean shopInformationBean = new ShopInformationBean();
shopInformationBean.setId(shopInformation.getId());
shopInformationBean.setName(shopInformation.getName());
shopInformationBean.setLevel(shopInformation.getLevel());
shopInformationBean.setPrice(shopInformation.getPrice().doubleValue());
shopInformationBean.setRemark(shopInformation.getRemark());
shopInformationBean.setSort(stringBuffer);
shopInformationBean.setQuantity(shopInformation.getQuantity());
shopInformationBean.setTransaction(shopInformation.getTransaction());
shopInformationBean.setUid(shopInformation.getUid());
shopInformationBean.setImage(shopInformation.getImage());
list.add(shopInformationBean);
}
model.addAttribute("shopInformationBean", list);
/**
*/
@Controller
public class SendEmailController {
@Resource
private UserInformationService userInformationService;
private static final Logger log = LoggerFactory.getLogger(SendEmailController.class);
//send the Email to the phone
@RequestMapping(value = "sendCode.do", method = {RequestMethod.POST, RequestMethod.GET})
@ResponseBody
public BaseResponse sendEmail(HttpServletRequest req, HttpServletResponse res,
@RequestParam String phone, @RequestParam String action,
@RequestParam String token) {
res.setContentType("text/html;charset=UTF-8");
//token,防止重复提交
String sendCodeToken = (String) req.getSession().getAttribute("token");
if (StringUtils.getInstance().isNullOrEmpty(sendCodeToken) || !sendCodeToken.equals(token)) {
return BaseResponse.fail();
}
//判断手机号码是否为正确
if (!StringUtils.getInstance().isPhone(phone)) {
return BaseResponse.fail();
}
//如果是忘记密码提交的发送短信
if ("forget".equals(action)) {
if (!isUserPhoneExists(phone)) {
//失败
return BaseResponse.fail();
}
} else if ("register".equals(action)) {
//失败
if (isUserPhoneExists(phone)) {
return BaseResponse.fail();
}
}
//get the random num to phone which should check the phone to judge the phone is belong user
return list;
}
//获取最详细的分类,第三层
private Specific selectSpecificBySort(int sort) {
return specificeService.selectByPrimaryKey(sort);
}
//获得第二层分类
private Classification selectClassificationByCid(int cid) {
return classificationService.selectByPrimaryKey(cid);
}
//获得第一层分类
private AllKinds selectAllKindsByAid(int aid) {
return allKindsService.selectByPrimaryKey(aid);
}
//获得第一层所有
private List<AllKinds> getAllKinds() {
return allKindsService.selectAll();
}
//根据第一层的id获取该层下的第二层
private List<Classification> selectAllClassification(int aid) {
return classificationService.selectByAid(aid);
}
//根据第二层的id获取其对应的第三层所有id
private List<Specific> selectAllSpecific(int cid) {
return specificeService.selectByCid(cid);
}
//获得商品总页数
private int getShopCounts() {
return shopInformationService.getCounts();
}
//获得商品留言总页数
private int getShopContextCounts(int sid) {
return shopContextService.getCounts(sid);
}
//获得商品留言,10条
private List<ShopContext> selectShopContextBySid(int sid, int start) {
return shopContextService.findById(sid, (start - 1) * 10);
}
}
shopInformation.setId(id);
try {
int result = shopInformationService.updateByPrimaryKeySelective(shopInformation);
if (result != 1) {
return "redirect:publish_product.do";
}
} catch (Exception e) {
e.printStackTrace();
return "redirect:publish_product.do";
}
goodsToken = TokenProccessor.getInstance().makeToken();
request.getSession().setAttribute("goodsToken", goodsToken);
model.addAttribute("token", goodsToken);
shopInformation = shopInformationService.selectByPrimaryKey(id);
model.addAttribute("userInformation", userInformation);
model.addAttribute("shopInformation", shopInformation);
model.addAttribute("action", 2);
model.addAttribute("sort", getSort(sort));
}
return "redirect:/my_publish_product_page.do";
}
//从发布的商品直接跳转到修改商品
@RequestMapping(value = "/modifiedMyPublishProduct.do")
public String modifiedMyPublishProduct(HttpServletRequest request, Model model,
@RequestParam int id) {
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return "redirect:/login.do";
}
String goodsToken = TokenProccessor.getInstance().makeToken();
request.getSession().setAttribute("goodsToken", goodsToken);
model.addAttribute("token", goodsToken);
ShopInformation shopInformation = shopInformationService.selectByPrimaryKey(id);
model.addAttribute("userInformation", userInformation);
model.addAttribute("shopInformation", shopInformation);
model.addAttribute("action", 2);
model.addAttribute("sort", getSort(shopInformation.getSort()));
return "page/publish_product";
}
//发表留言
@RequestMapping(value = "/insertShopContext.do")
@ResponseBody
public Map insertShopContext(@RequestParam int id, @RequestParam String context, @RequestParam String token,
HttpServletRequest request) {
String goodsToken = (String) request.getSession().getAttribute("goodsToken");
Map<String, String> map = new HashMap<>();
}
return map;
}
//删除求购
@RequestMapping(value = "/deleteUserWant.do")
public String deleteUserWant(HttpServletRequest request, @RequestParam int id) {
// Map<String, Integer> map = new HashMap<>();
if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
return "redirect:/login.do";
}
UserWant userWant = new UserWant();
userWant.setId(id);
userWant.setDisplay(0);
try {
int result = userWantService.updateByPrimaryKeySelective(userWant);
if (result != 1) {
return "redirect:my_require_product.do";
}
} catch (Exception e) {
e.printStackTrace();
}
return "redirect:my_require_product.do";
}
//收藏
//add the userCollection
@RequestMapping(value = "/addUserCollection.do")
@ResponseBody
public BaseResponse addUserCollection(HttpServletRequest request, @RequestParam int sid) {
//determine whether the user exits
if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
//if the user no exits in the session,
return BaseResponse.fail();
}
UserCollection userCollection = new UserCollection();
userCollection.setModified(new Date());
userCollection.setSid(sid);
userCollection.setUid((Integer) request.getSession().getAttribute("uid"));
//begin insert the userCollection
int result = userCollectionService.insertSelective(userCollection);
if (result != 1) {
return BaseResponse.fail();
}
return BaseResponse.success();
}
// delete the userCollection
@RequestMapping(value = "/deleteUserCollection.do")
@ResponseBody
public BaseResponse deleteUserCollection(HttpServletRequest request, @RequestParam int ucid) {
if (StringUtils.getInstance().isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
String publishUserWantToken = TokenProccessor.getInstance().makeToken();
request.getSession().setAttribute("publishUserWantToken", publishUserWantToken);
model.addAttribute("token", publishUserWantToken);
model.addAttribute("userInformation", userInformation);
UserWant userWant = userWantService.selectByPrimaryKey(id);
model.addAttribute("userWant", userWant);
String sort = getSort(userWant.getSort());
model.addAttribute("sort", sort);
return "page/modified_require_product";
}
//publish userWant,发布求购
@RequestMapping(value = "/publishUserWant.do")
// @ResponseBody
public String publishUserWant(HttpServletRequest request, Model model,
@RequestParam String name,
@RequestParam int sort, @RequestParam int quantity,
@RequestParam double price, @RequestParam String remark,
@RequestParam String token) {
// Map<String, Integer> map = new HashMap<>();
//determine whether the user exits
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
//if the user no exits in the session,
// map.put("result", 2);
return "redirect:/login.do";
}
String publishUserWantToke = (String) request.getSession().getAttribute("publishUserWantToken");
if (StringUtils.getInstance().isNullOrEmpty(publishUserWantToke) || !publishUserWantToke.equals(token)) {
// map.put("result", 2);
return "redirect:require_product.do?error=3";
} else {
request.getSession().removeAttribute("publishUserWantToken");
}
// name = StringUtils.replaceBlank(name);
// remark = StringUtils.replaceBlank(remark);
// name = StringUtils.getInstance().txtReplace(name);
// remark = StringUtils.getInstance().txtReplace(remark);
try {
if (name.length() < 1 || remark.length() < 1 || name.length() > 25 || remark.length() > 25) {
return "redirect:require_product.do";
}
} catch (Exception e) {
e.printStackTrace();
return "redirect:require_product.do?error=1";
}
UserWant userWant = new UserWant();
userWant.setModified(new Date());
return "redirect:/login.do";
}
String goodsToken = TokenProccessor.getInstance().makeToken();
request.getSession().setAttribute("goodsToken", goodsToken);
model.addAttribute("shopInformation", new ShopInformation());
model.addAttribute("action", 1);
model.addAttribute("token", goodsToken);
return "page/publish_product";
}
//模糊查询商品
@RequestMapping(value = "/findShopByName.do")
public String findByName(HttpServletRequest request, Model model,
@RequestParam String name) {
try {
List<ShopInformation> shopInformations = shopInformationService.selectByName(name);
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
userInformation = new UserInformation();
model.addAttribute("userInformation", userInformation);
} else {
model.addAttribute("userInformation", userInformation);
}
List<ShopInformationBean> shopInformationBeans = new ArrayList<>();
String sortName;
for (ShopInformation shopInformation : shopInformations) {
int sort = shopInformation.getSort();
sortName = getSort(sort);
ShopInformationBean shopInformationBean = new ShopInformationBean();
shopInformationBean.setId(shopInformation.getId());
shopInformationBean.setName(shopInformation.getName());
shopInformationBean.setLevel(shopInformation.getLevel());
shopInformationBean.setRemark(shopInformation.getRemark());
shopInformationBean.setPrice(shopInformation.getPrice().doubleValue());
shopInformationBean.setQuantity(shopInformation.getQuantity());
shopInformationBean.setTransaction(shopInformation.getTransaction());
shopInformationBean.setSort(sortName);
shopInformationBean.setUid(shopInformation.getUid());
shopInformationBean.setImage(shopInformation.getImage());
shopInformationBeans.add(shopInformationBean);
}
model.addAttribute("shopInformationBean", shopInformationBeans);
} catch (Exception e) {
e.printStackTrace();
return "redirect:mall_page.do";
}
return "page/mall_page";
}
//进入查看商品详情
@RequestMapping(value = "/selectById.do")
public String selectById(@RequestParam int id,
HttpServletRequest request, Model model) {
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
map.put("start", (counts - 1) * 12);
map.put("end", 12);
return shopInformationService.selectTen(map);
}
// //通过id查看商品详情
// @RequestMapping(value = "/showShop")
// public String showShop(@RequestParam int id, HttpServletRequest request, Model model) {
// ShopInformation shopInformation =
// }
//获取最详细的分类,第三层
private Specific selectSpecificBySort(int sort) {
return specificeService.selectByPrimaryKey(sort);
}
//获得第二层分类
private Classification selectClassificationByCid(int cid) {
return classificationService.selectByPrimaryKey(cid);
}
//获得第一层分类
private AllKinds selectAllKindsByAid(int aid) {
return allKindsService.selectByPrimaryKey(aid);
}
private String getSort(int sort) {
StringBuilder sb = new StringBuilder();
Specific specific = selectSpecificBySort(sort);
int cid = specific.getCid();
Classification classification = selectClassificationByCid(cid);
int aid = classification.getAid();
AllKinds allKinds = selectAllKindsByAid(aid);
String allName = allKinds.getName();
sb.append(allName);
sb.append("-");
sb.append(classification.getName());
sb.append("-");
sb.append(specific.getName());
return sb.toString();
}
}
/**
*/
@RestController
public class ForgetController {
@Resource
private UserPasswordService userPasswordService;
@Resource
private UserInformationService userInformationService;
@RequestMapping(value = "checkCode.do", method = {RequestMethod.POST, RequestMethod.GET})
public Map checkPhone(HttpServletRequest request, Model model,
@RequestParam String code, @RequestParam String token) {
Map<String, Integer> map = new HashMap<>();
String name = request.getParameter("name");
if (!StringUtils.getInstance().isNullOrEmpty(name)) {
request.getSession().setAttribute("name", name);
}
String checkCodeToken = (String) request.getSession().getAttribute("token");
if (StringUtils.getInstance().isNullOrEmpty(checkCodeToken) || !checkCodeToken.equals(token)) {
map.put("result", 0);
return map;
}
//验证码错误
if (!checkCodePhone(code, request)) {
map.put("result", 0);
return map;
}
map.put("result", 1);
shopInformation.setLevel(level);
shopInformation.setName(name);
shopInformation.setId(id);
try {
int result = shopInformationService.updateByPrimaryKeySelective(shopInformation);
if (result != 1) {
return "redirect:publish_product.do";
}
} catch (Exception e) {
e.printStackTrace();
return "redirect:publish_product.do";
}
goodsToken = TokenProccessor.getInstance().makeToken();
request.getSession().setAttribute("goodsToken", goodsToken);
model.addAttribute("token", goodsToken);
shopInformation = shopInformationService.selectByPrimaryKey(id);
model.addAttribute("userInformation", userInformation);
model.addAttribute("shopInformation", shopInformation);
model.addAttribute("action", 2);
model.addAttribute("sort", getSort(sort));
}
return "redirect:/my_publish_product_page.do";
}
//从发布的商品直接跳转到修改商品
@RequestMapping(value = "/modifiedMyPublishProduct.do")
public String modifiedMyPublishProduct(HttpServletRequest request, Model model,
@RequestParam int id) {
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return "redirect:/login.do";
}
String goodsToken = TokenProccessor.getInstance().makeToken();
request.getSession().setAttribute("goodsToken", goodsToken);
model.addAttribute("token", goodsToken);
ShopInformation shopInformation = shopInformationService.selectByPrimaryKey(id);
model.addAttribute("userInformation", userInformation);
model.addAttribute("shopInformation", shopInformation);
model.addAttribute("action", 2);
model.addAttribute("sort", getSort(shopInformation.getSort()));
return "page/publish_product";
}
//发表留言
@RequestMapping(value = "/insertShopContext.do")
@ResponseBody
u.setModified(userWant.getModified());
u.setName(userWant.getName());
list.add(u);
}
model.addAttribute("list", list);
return "page/require_mall";
}
//通过id查看商品的详情
@RequestMapping(value = "/findShopById.do")
@ResponseBody
public ShopInformation findShopById(@RequestParam int id) {
return shopInformationService.selectByPrimaryKey(id);
}
//通过分类选择商品
@RequestMapping(value = "/selectBySort.do")
@ResponseBody
public List<ShopInformation> selectBySort(@RequestParam int sort) {
return shopInformationService.selectBySort(sort);
}
//分页查询
@RequestMapping(value = "/selectByCounts.do")
@ResponseBody
public List<ShopInformation> selectByCounts(@RequestParam int counts) {
Map<String, Integer> map = new HashMap<>();
map.put("start", (counts - 1) * 12);
map.put("end", 12);
return shopInformationService.selectTen(map);
}
// //通过id查看商品详情
// @RequestMapping(value = "/showShop")
// public String showShop(@RequestParam int id, HttpServletRequest request, Model model) {
// ShopInformation shopInformation =
// }
//获取最详细的分类,第三层
private Specific selectSpecificBySort(int sort) {
return specificeService.selectByPrimaryKey(sort);
}
//获得第二层分类
private Classification selectClassificationByCid(int cid) {
return classificationService.selectByPrimaryKey(cid);
}
//获得第一层分类
private AllKinds selectAllKindsByAid(int aid) {
return allKindsService.selectByPrimaryKey(aid);
}
private String getSort(int sort) {
StringBuilder sb = new StringBuilder();
userInformation = new UserInformation();
model.addAttribute("userInformation", userInformation);
// list.add(shopCar);
return "redirect:/login.do";
} else {
model.addAttribute("userInformation", userInformation);
}
int uid = userInformation.getId();
List<GoodsCar> goodsCars = goodsCarService.selectByUid(uid);
List<GoodsCarBean> goodsCarBeans = new ArrayList<>();
for (GoodsCar goodsCar : goodsCars) {
GoodsCarBean goodsCarBean = new GoodsCarBean();
goodsCarBean.setUid(goodsCar.getUid());
goodsCarBean.setSid(goodsCar.getSid());
goodsCarBean.setModified(goodsCar.getModified());
goodsCarBean.setId(goodsCar.getId());
goodsCarBean.setQuantity(goodsCar.getQuantity());
ShopInformation shopInformation = shopInformationService.selectByPrimaryKey(goodsCar.getSid());
goodsCarBean.setName(shopInformation.getName());
goodsCarBean.setRemark(shopInformation.getRemark());
goodsCarBean.setImage(shopInformation.getImage());
goodsCarBean.setPrice(shopInformation.getPrice().doubleValue());
goodsCarBean.setSort(getSort(shopInformation.getSort()));
goodsCarBeans.add(goodsCarBean);
}
model.addAttribute("list", goodsCarBeans);
return "page/shopping_cart";
}
// //通过购物车的id获取购物车里面的商品
// @RequestMapping(value = "/selectGoodsOfShopCar")
// @ResponseBody
// public List<GoodsCar> selectGoodsCar(HttpServletRequest request) {
// List<GoodsCar> list = new ArrayList<>();
// GoodsCar goodsCar = new GoodsCar();
// if (Empty.isNullOrEmpty(request.getSession().getAttribute("userInformation"))) {
// list.add(goodsCar);
// return list;
// }
// try {
// int scid = shopCarService.selectByUid((Integer) request.getSession().getAttribute("uid")).getId();
// list = goodsCarService.selectByUid(scid);
// return list;
// } catch (Exception e) {
// e.printStackTrace();
// return list;
// }
// }
//添加到购物车
@RequestMapping(value = "/insertGoodsCar.do")
model.addAttribute("shopInformationBean", list);
return "page/personal/my_publish_product_page";
}
//更新商品信息
private String getSort(int sort) {
StringBuilder sb = new StringBuilder();
Specific specific = selectSpecificBySort(sort);
int cid = specific.getCid();
Classification classification = selectClassificationByCid(cid);
int aid = classification.getAid();
AllKinds allKinds = selectAllKindsByAid(aid);
sb.append(allKinds.getName());
sb.append("-");
sb.append(classification.getName());
sb.append("-");
sb.append(specific.getName());
return sb.toString();
}
//查看用户收藏的货物的总数
private int getCollectionCounts(int uid) {
int counts;
try {
counts = userCollectionService.getCounts(uid);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
return counts;
}
//查看收藏,一次10个
private List<UserCollection> selectContectionByUid(int uid, int start) {
try {
return userCollectionService.selectByUid(uid, (start - 1) * 10);
} catch (Exception e) {
e.printStackTrace();
list.add(shopInformationBean);
}
model.addAttribute("shopInformationBean", list);
} catch (Exception e) {
e.printStackTrace();
return "page/login_page";
}
return "index";
}
//进入商城
@RequestMapping(value = "/mall_page.do")
public String mallPage(HttpServletRequest request, Model model) {
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
userInformation = new UserInformation();
model.addAttribute("userInformation", userInformation);
} else {
model.addAttribute("userInformation", userInformation);
}
try {
List<ShopInformation> shopInformations = selectTen(1, 12);
List<ShopInformationBean> list = new ArrayList<>();
int counts = getShopCounts();
model.addAttribute("shopInformationCounts", counts);
String sortName;
for (ShopInformation shopInformation : shopInformations) {
int sort = shopInformation.getSort();
sortName = getSortName(sort);
ShopInformationBean shopInformationBean = new ShopInformationBean();
shopInformationBean.setId(shopInformation.getId());
shopInformationBean.setName(shopInformation.getName());
shopInformationBean.setLevel(shopInformation.getLevel());
shopInformationBean.setRemark(shopInformation.getRemark());
shopInformationBean.setPrice(shopInformation.getPrice().doubleValue());
shopInformationBean.setSort(sortName);
shopInformationBean.setQuantity(shopInformation.getQuantity());
shopInformationBean.setTransaction(shopInformation.getTransaction());
shopInformationBean.setUid(shopInformation.getUid());
shopInformationBean.setImage(shopInformation.getImage());
list.add(shopInformationBean);
}
model.addAttribute("shopInformationBean", list);
} catch (Exception e) {
e.printStackTrace();
return "page/login_page";
}
return "page/mall_page";
}