基于javaweb+mysql的springboot体育用品商城(java+springboot+jsp+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot体育用品商城(java+springboot+jsp+maven+mysql)
本项目为前后台管理系统,包括管理员与普通用户两种角色;
管理员角色包含以下功能: 管理员登录,用户管理,商品类型管理,商品管理,订单信息管理,用户留言管理,资讯管理等功能。
用户角色包含以下功能: 用户首页,用户登录,商品推荐,资讯信息,留言板,查看商品,提交订单,查看订单信息,个人资料管理等功能。
ps:推荐模块用了协同过滤推荐算法,下订单模块用的是百度地图api。本商城可以修改为任意商城不止是体育商城。
//回复留言信息
adminManager.addSblogReply(paramsSblogReply);;
setSuccessTip("回复留言成功", "Admin_listSblogs.action", model);
} catch (Exception e) {
setErrorTip("回复留言异常", "Admin_listSblogs.action", model);
}
return "infoTip";
}
/**
* @Title: listGoodsTypes
* @Description: 查询商品类型
* @return String
*/
@RequestMapping(value="admin/Admin_listGoodsTypes.action")
public String listGoodsTypes(GoodsType paramsGoodsType,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
if (paramsGoodsType==null) {
paramsGoodsType = new GoodsType();
}
//设置分页信息
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
paperUtil.setPagination(paramsGoodsType);
//总的条数
int[] sum={0};
//查询商品类型列表
List<GoodsType> goodsTypes = adminManager.listGoodsTypes(paramsGoodsType,sum);
model.addAttribute("goodsTypes", goodsTypes);
model.addAttribute("paramsGoodsType", paramsGoodsType);
paperUtil.setTotalCount(sum[0]);
} catch (Exception e) {
setErrorTip("查询商品类型异常", "main.jsp", model);
return "infoTip";
}
return "goodsTypeShow";
}
/**
* @Title: addGoodsTypeShow
* @Description: 显示添加商品类型页面
* @return String
*/
@RequestMapping(value="admin/Admin_addGoodsTypeShow.action",method=RequestMethod.GET)
public String addGoodsTypeShow(){
return "goodsTypeEdit";
}
orders.setOrders_no(paramsOrders.getOrders_no());
List<OrdersDetail> listsDetails = ordersDetailDao.listOrdersDetailsByOrder(orders);
if(listsDetails != null) {
for(OrdersDetail ordersDetail:listsDetails) {
DingDan dingdan = new DingDan();
dingdan.setGoods_id(ordersDetail.getGoods_id());
dingdan.setTime(new Date());
dingdan.setUser_id(user.getUser_id());
if(dingDanDao.getDingDan(dingdan) == null)
dingDanDao.addDingDan(dingdan);
}
}
System.out.println(listsDetails.size());
} catch (Exception e) {
e.printStackTrace();
jsonData.setErrorReason("提交订单失败");
return jsonData;
}
return jsonData;
}
/**
* @Title: listSblogs
* @Description: 留言信息
* @return String
*/
@RequestMapping(value="page_listSblogs.action")
public String listSblogs(Sblog paramsSblog,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//查询留言信息集合
if (paramsSblog==null) {
paramsSblog = new Sblog();
}
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
//设置分页信息
paperUtil.setPagination(paramsSblog);
int[] sum={0};
List<Sblog> sblogs = indexManager.listSblogs(paramsSblog,sum);
model.addAttribute("sblogs", sblogs);
return "infoTip";
}
/**
* @Title: listSblogs
* @Description: 查询留言信息
* @return String
*/
@RequestMapping(value="admin/Admin_listSblogs.action")
public String listSblogs(Sblog paramsSblog,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
if (paramsSblog==null) {
paramsSblog = new Sblog();
}
//设置分页信息
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
paperUtil.setPagination(paramsSblog);
int[] sum={0};
List<Sblog> sblogs = adminManager.listSblogs(paramsSblog,sum);
model.addAttribute("sblogs", sblogs);
model.addAttribute("paramsSblog", paramsSblog);
paperUtil.setTotalCount(sum[0]);
} catch (Exception e) {
setErrorTip("查询留言信息异常", "main.jsp", model);
return "infoTip";
}
return "sblogShow";
}
@RequestMapping(value="admin/Admin_addzixun.action")
public String Admin_addzixun( PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
return "zixunadd";
}
@RequestMapping(value="admin/Admin_editzixun.action",method=RequestMethod.GET)
public String Admin_editzixun(Integer id,
return "infoTip";
}
/**
* @Title: editUser
* @Description: 编辑注册用户
* @return String
*/
@RequestMapping(value="admin/Admin_editUser.action",method=RequestMethod.GET)
public String editUser(User paramsUser,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//得到注册用户
User user = adminManager.queryUser(paramsUser);
model.addAttribute("user", user);
} catch (Exception e) {
setErrorTip("查询注册用户异常", "Admin_listUsers.action", model);
return "infoTip";
}
return "userEdit";
}
/**
* @Title: saveUser
* @Description: 保存编辑注册用户
* @return String
*/
@RequestMapping(value="admin/Admin_saveUser.action",method=RequestMethod.POST)
public String saveUser(User paramsUser,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//保存编辑注册用户
adminManager.updateUser(paramsUser);
setSuccessTip("编辑成功", "Admin_listUsers.action", model);
} catch (Exception e) {
setErrorTip("编辑注册用户异常", "Admin_listUsers.action", model);
return "infoTip";
}
}
adminManager.updateManager(paramsManager);
//更新session
if (admin!=null) {
admin.setManager_pass(paramsManager.getManager_pass());
httpSession.setAttribute("admin", admin);
}
setSuccessTip("修改成功", "modifyPwd.jsp", model);
} catch (Exception e) {
setErrorTip("修改异常", "modifyPwd.jsp", model);
}
return "infoTip";
}
/**
* @Title: listUsers
* @Description: 查询注册用户
* @return String
*/
@RequestMapping(value="admin/Admin_listUsers.action")
public String listUsers(User paramsUser,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
if (paramsUser==null) {
paramsUser = new User();
}
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
//设置分页信息
paperUtil.setPagination(paramsUser);
//总的条数
int[] sum={0};
//查询注册用户列表
List<User> users = adminManager.listUsers(paramsUser,sum);
model.addAttribute("users", users);
model.addAttribute("paramsUser", paramsUser);
paperUtil.setTotalCount(sum[0]);
} catch (Exception e) {
setErrorTip("查询注册用户异常", "main.jsp", model);
return "infoTip";
}
return "userShow";
}
/**
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
paperUtil.setPagination(zixun);
//总的条数
int[] sum={0};
//查询商品类型列表
List<Zixun> zixuns = zixunMapper.selectByExample(new ZixunExample());
model.addAttribute("zixuns", zixuns);
// model.addAttribute("zixun", zixun);
paperUtil.setTotalCount(zixuns.size());
} catch (Exception e) {
setErrorTip("查询商品类型异常", "main.jsp", model);
return "infoTip";
}
return "zixunlist";
}
@RequestMapping(value="admin/updatezixun.action")
public String updatezixun(Zixun zixun,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
zixun.setTime(new Date());
ZixunExample zixunExample = new ZixunExample();
Criteria criteria = zixunExample.createCriteria();
criteria.andIdEqualTo(zixun.getId());
zixunMapper.updateByExampleSelective(zixun, zixunExample);
try {
if (zixun==null) {
zixun = new Zixun();
}
//设置分页信息
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
paperUtil.setPagination(zixun);
//总的条数
int[] sum={0};
//查询商品类型列表
List<Zixun> zixuns = zixunMapper.selectByExample(new ZixunExample());
}
return "goodsDetail";
}
/**
* @Title: listCard
* @Description: 查询购物车
* @return String
*/
@RequestMapping(value="page_listCard.action")
public String listCard(ModelMap model,HttpSession httpSession){
try {
//查询购物车
List<OrdersDetail> ordersDetails = new ArrayList<OrdersDetail>();
User user = (User)httpSession.getAttribute("userFront");
if(user == null) {
model.addAttribute("tip","登录超时请重新登录!");
return "login";
}
GouWuChe gouwuche = new GouWuChe();
gouwuche.setUser_id(user.getUser_id());
List<GouWuChe> gouWuChes = gouWuCheDao.listGouWuChes(gouwuche);
if(gouWuChes != null) {
for(GouWuChe tempChe : gouWuChes) {
OrdersDetail ordersDetail = new OrdersDetail();
Goods goods = new Goods();
goods.setGoods_id(tempChe.getGoods_id());
Goods dbGoods = goodsDao.getGoods(goods);
ordersDetail.setGoods_id(dbGoods.getGoods_id());
ordersDetail.setGoods_name(dbGoods.getGoods_name());
ordersDetail.setGoods_price(dbGoods.getGoods_price());
ordersDetail.setGoods_discount(dbGoods.getGoods_discount());
ordersDetail.setGoods_count(tempChe.getCount());
ordersDetail.setGoods_money(dbGoods.getGoods_price()*tempChe.getCount());
ordersDetails.add(ordersDetail);
}
}
httpSession.removeAttribute("ordersDetails");
httpSession.setAttribute("ordersDetails", ordersDetails);
model.addAttribute("ordersDetails", ordersDetails);
} catch (Exception e) {
e.printStackTrace();
return "error";
}
@SuppressWarnings("unchecked")
public void delGoodsFromCard(int goods_id,HttpSession httpSession) {
//查询购物车
List<OrdersDetail> card = (List<OrdersDetail>) httpSession.getAttribute("card");
if (card!=null) {
for (OrdersDetail ordersDetail : card) {
if (ordersDetail.getGoods_id()==goods_id) {
card.remove(ordersDetail);
break;
}
}
}
httpSession.setAttribute("card", card);
}
/**
* @Title: clearCard
* @Description: 清空购物车
*/
public void clearCard(HttpSession httpSession) {
//清空购物车
httpSession.removeAttribute("card");
}
@SuppressWarnings("unchecked")
private OrdersDetail getGoodsFromCard(int goods_id,HttpSession httpSession) {
//查询购物车
List<OrdersDetail> card = (List<OrdersDetail>) httpSession.getAttribute("card");
if (card!=null) {
for (OrdersDetail ordersDetail : card) {
if (ordersDetail.getGoods_id()==goods_id) {
return ordersDetail;
}
}
}else {
return null;
}
return null;
}
/**
* @Title: addOrders
* @Description: 添加商品订单
* @param orders
* @return Orders
List<User> users = userDao.listUsers(user);
return users;
}
/**
* @Title: queryUser
* @Description: 用户单个查询
* @param user
* @return User
*/
public User queryUser(User user) {
User _user = userDao.getUser(user);
return _user;
}
/**
* @Title: updateUser
* @Description: 更新用户信息
* @param user
* @return void
*/
public void updateUser(User user) {
if (!StringUtil.isEmptyString(user.getUser_pass())) {
user.setUser_pass(Md5.makeMd5(user.getUser_pass()));
}
userDao.updateUser(user);
}
/**
* @Title: listGoodsTypes
* @Description: 商品类型查询
* @param goodsType
* @return List<GoodsType>
*/
public List<GoodsType> listGoodsTypes(GoodsType goodsType, int[] sum) {
if (sum != null) {
sum[0] = goodsTypeDao.listGoodsTypesCount(goodsType);
}
List<GoodsType> goodsTypes = goodsTypeDao.listGoodsTypes(goodsType);
return goodsTypes;
}
/**
* @Title: listGoodss
* @Description: 查询商品信息
* @param goods
@Controller
public class IndexAction{
@Autowired
IndexManager indexManager;
@Autowired
IGouWuCheDao gouWuCheDao;
@Autowired
IDingDanDao dingDanDao;
User admin = new User();
admin.setUser_id(paramsUser.getUser_id());
admin = indexManager.queryUser(admin);
httpSession.setAttribute("userFront", admin);
} catch (Exception e) {
e.printStackTrace();
jsonData.setErrorReason("后台服务器异常");
return jsonData;
}
return jsonData;
}
/**
* @Title: saveUserFrontPass
* @Description: 保存修改个人密码
* @return String
*/
@RequestMapping(value="page_saveUserFrontPass.action",method=RequestMethod.POST)
@ResponseBody
public JSONData saveUserFrontPass(User paramsUser,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
JSONData jsonData = new JSONData();
try {
//保存修改个人密码
User userFront = (User)httpSession.getAttribute("userFront");
if (!userFront.getUser_pass().equals(Md5.makeMd5(paramsUser.getUser_passOld()))) {
jsonData.setErrorReason("原密码不正确");
return jsonData;
}
indexManager.updateUser(paramsUser);
//更新session
if (userFront!=null) {
userFront.setUser_pass(paramsUser.getUser_pass());
httpSession.setAttribute("userFront", userFront);
}
} catch (Exception e) {
e.printStackTrace();
jsonData.setErrorReason("后台服务器异常");
return jsonData;
}
return jsonData;
}
/**
}
/**
* @Title: listSblogs
* @Description: 留言信息
* @return String
*/
@RequestMapping(value="page_listSblogs.action")
public String listSblogs(Sblog paramsSblog,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//查询留言信息集合
if (paramsSblog==null) {
paramsSblog = new Sblog();
}
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
//设置分页信息
paperUtil.setPagination(paramsSblog);
int[] sum={0};
List<Sblog> sblogs = indexManager.listSblogs(paramsSblog,sum);
model.addAttribute("sblogs", sblogs);
paperUtil.setTotalCount(sum[0]);
} catch (Exception e) {
e.printStackTrace();
return "error";
}
return "sblog";
}
/**
* @Title: addSblog
* @Description: 新增留言
* @return String
*/
@RequestMapping(value="page_addSblog.action")
@ResponseBody
public JSONData addSblog(Sblog paramsSblog,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
JSONData jsonData = new JSONData();
oldDetail.setGoods_count(ordersDetail.getGoods_count());
double goods_money = oldDetail.getGoods_price()*oldDetail.getGoods_count()*oldDetail.getGoods_discount()/10.0;
oldDetail.setGoods_money(Math.round(goods_money*10)/10.0);
card.add(oldDetail);
httpSession.setAttribute("card", card);
}
/**
* @Title: delGoodsFromCard
* @Description: 从购物车删除商品
* @param goods_id
*/
@SuppressWarnings("unchecked")
public void delGoodsFromCard(int goods_id,HttpSession httpSession) {
//查询购物车
List<OrdersDetail> card = (List<OrdersDetail>) httpSession.getAttribute("card");
if (card!=null) {
for (OrdersDetail ordersDetail : card) {
if (ordersDetail.getGoods_id()==goods_id) {
card.remove(ordersDetail);
break;
}
}
}
httpSession.setAttribute("card", card);
}
/**
* @Title: clearCard
* @Description: 清空购物车
*/
public void clearCard(HttpSession httpSession) {
//清空购物车
httpSession.removeAttribute("card");
}
@SuppressWarnings("unchecked")
private OrdersDetail getGoodsFromCard(int goods_id,HttpSession httpSession) {
//查询购物车
List<OrdersDetail> card = (List<OrdersDetail>) httpSession.getAttribute("card");
if (card!=null) {
for (OrdersDetail ordersDetail : card) {
if (ordersDetail.getGoods_id()==goods_id) {
return ordersDetail;
}
}
}else {
return null;
}
String allowedTypes = props.getProperty("allowedTypes");
if ("1".equals(num)) {
allowedTypes = props.getProperty("allowedTypes1");
}else if ("2".equals(num)) {
allowedTypes = props.getProperty("allowedTypes2");
}else if ("3".equals(num)) {
allowedTypes = props.getProperty("allowedTypes3");
}
//上传文件
String errorString=UploadFile.upload(file, saveFile, file.getContentType(), file.getSize(), allowedTypes,Long.parseLong(props.getProperty("maximunSize")));
//判断上传结果
if(!"".equals(errorString))
{
System.out.println(errorString);
model.addAttribute("tip", "no");
model.addAttribute("errorString", errorString);
return returnPage;
}
model.addAttribute("tip", "ok");
model.addAttribute("filename",file_name);
model.addAttribute("filenameGBK",old_name);
model.addAttribute("filelength",Math.round(file.getSize()/1024.0));
return returnPage;
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
model.addAttribute("tip", "no");
model.addAttribute("errorString", "后台服务器异常");
return returnPage;
}
}
}
package com.soft.demo.controller;
//保存修改个人信息
adminManager.updateManager(paramsManager);
//更新session
Manager admin = new Manager();
admin.setManager_id(paramsManager.getManager_id());
admin = adminManager.queryManager(admin);
httpSession.setAttribute("admin", admin);
setSuccessTip("编辑成功", "modifyInfo.jsp", model);
} catch (Exception e) {
e.printStackTrace();
setErrorTip("编辑异常", "modifyInfo.jsp", model);
}
return "infoTip";
}
/**
* @Title: saveAdminPass
* @Description: 保存修改个人密码
* @return String
*/
@RequestMapping(value="admin/Admin_saveAdminPass.action",method=RequestMethod.POST)
public String saveAdminPass(Manager paramsManager,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//验证用户会话是否失效
if (!validateAdmin(httpSession)) {
return "loginTip";
}
//保存修改个人密码
Manager admin = (Manager)httpSession.getAttribute("admin");
if (!admin.getManager_pass().equals(Md5.makeMd5(paramsManager.getManager_passOld()))) {
setErrorTip("修改异常,原密码不正确", "modifyPwd.jsp", model);
return "infoTip";
}
adminManager.updateManager(paramsManager);
//更新session
if (admin!=null) {
admin.setManager_pass(paramsManager.getManager_pass());
httpSession.setAttribute("admin", admin);
}
System.out.println(dingdanList);
System.out.println(pinglunList);
Map<Integer, Double> map = new HashMap<Integer, Double>();
for(Integer id:gouwucheList) {
double similar = getSimilarWithUserByGouWuChe(userFront.getUser_id(), id);
map.put(id, similar);
}
for(Integer id:dingdanList) {
double similar = getSimilarWithUserByDingdan(userFront.getUser_id(), id);
if(map.get(id) == null) {
map.put(id, similar);
}else {
map.put(id,map.get(id)+similar);
}
}
for(Integer id:gouwucheList) {
double similar = getSimilarWithUserByPinglun(userFront.getUser_id(), id);
if(map.get(id) == null) {
map.put(id, similar);
}else {
map.put(id,map.get(id)+similar);
}
}
List<Similar> list = new ArrayList<Similar>();
if(map.size() != 0) {
for(Map.Entry<Integer, Double> entry:map.entrySet()){
Similar similar = new Similar();
similar.setUserid(entry.getKey());
similar.setSimilar(entry.getValue());
list.add(similar);
}
}
Collections.sort(list, new Comparator<Similar>() {
@Override
public int compare(Similar arg0, Similar arg1) {
// TODO Auto-generated method stub
if(arg0.getSimilar()>arg1.getSimilar()) {
return 0;
}else {
return 1;
}
}
});
//删除注册用户
adminManager.delUsers(paramsUser);
setSuccessTip("删除注册用户成功", "Admin_listUsers.action", model);
} catch (Exception e) {
setErrorTip("删除注册用户异常", "Admin_listUsers.action", model);
}
return "infoTip";
}
/**
* @Title: listSblogs
* @Description: 查询留言信息
* @return String
*/
@RequestMapping(value="admin/Admin_listSblogs.action")
public String listSblogs(Sblog paramsSblog,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
if (paramsSblog==null) {
paramsSblog = new Sblog();
}
//设置分页信息
if (paperUtil==null) {
paperUtil = new PaperUtil();
}
paperUtil.setPagination(paramsSblog);
int[] sum={0};
List<Sblog> sblogs = adminManager.listSblogs(paramsSblog,sum);
model.addAttribute("sblogs", sblogs);
model.addAttribute("paramsSblog", paramsSblog);
paperUtil.setTotalCount(sum[0]);
} catch (Exception e) {
setErrorTip("查询留言信息异常", "main.jsp", model);
return "infoTip";
}
return "sblogShow";
}
@RequestMapping(value="admin/Admin_addzixun.action")
public String Admin_addzixun( PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
return "zixunadd";
}
sum[0] = ordersDetailDao.listOrdersDetailsCount(ordersDetail);
}
List<OrdersDetail> ordersDetails = ordersDetailDao.listOrdersDetails(ordersDetail);
return ordersDetails;
}
/**
* @Title: addEvaluate
* @Description: 添加商品评价
* @param evaluate
* @return void
*/
public void addEvaluate(Evaluate evaluate) {
//添加商品评价
evaluate.setEvaluate_date(DateUtil.getCurDateTime());
evaluateDao.addEvaluateBatch(evaluate);
//更新订单为已评价
Orders orders = new Orders();
orders.setOrders_no(evaluate.getOrders_no());
orders.setOrders_flag(4);
ordersDao.updateOrders(orders);
}
/**
* @Title: listSblogs
* @Description: 查询留言信息
* @param sblog
* @return List<Sblog>
*/
public List<Sblog> listSblogs(Sblog sblog,int[] sum){
if (sum!=null) {
sum[0] = sblogDao.listSblogsCount(sblog);
}
List<Sblog> sblogs = sblogDao.listSblogs(sblog);
if (sblogs!=null) {
for (Sblog sblog2 : sblogs) {
SblogReply sblogReply = new SblogReply();
sblogReply.setStart(-1);
sblogReply.setSblog_id(sblog2.getSblog_id());
List<SblogReply> replys = sblogReplyDao.listSblogReplys(sblogReply);
if (replys!=null) {
sblog2.setReplys(replys);
}
}
}
return "infoTip";
}
return "sblogDetail";
}
/**
* @Title: delSblogs
* @Description: 删除留言信息
* @return String
*/
@RequestMapping(value="admin/Admin_delSblogs.action")
public String delSblogs(Sblog paramsSblog,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//删除留言信息
adminManager.delSblogs(paramsSblog);
setSuccessTip("删除留言信息成功", "Admin_listSblogs.action", model);
} catch (Exception e) {
setErrorTip("删除留言信息异常", "Admin_listSblogs.action", model);
}
return "infoTip";
}
/**
* @Title:
* @Title: replySblog
* @Description: 回复留言信息
* @return String
*/
@RequestMapping(value="admin/Admin_replySblog.action",method=RequestMethod.GET)
public String replySblog(Sblog paramsSblog,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
//得到留言信息
Sblog sblog = adminManager.querySblog(paramsSblog);
model.addAttribute("sblog", sblog);
} catch (Exception e) {
setErrorTip("查询留言异常", "Admin_listSblogs.action", model);
return "infoTip";
}
return "sblogReply";
}
/**
* @Title: saveSblogReply
* @Description: 回复留言信息
//文件类型限制
String allowedTypes = props.getProperty("allowedTypes");
if ("1".equals(num)) {
allowedTypes = props.getProperty("allowedTypes1");
}else if ("2".equals(num)) {
allowedTypes = props.getProperty("allowedTypes2");
}else if ("3".equals(num)) {
allowedTypes = props.getProperty("allowedTypes3");
}
//上传文件
String errorString=UploadFile.upload(file, saveFile, file.getContentType(), file.getSize(), allowedTypes,Long.parseLong(props.getProperty("maximunSize")));
//判断上传结果
if(!"".equals(errorString))
{
System.out.println(errorString);
model.addAttribute("tip", "no");
model.addAttribute("errorString", errorString);
return returnPage;
}
model.addAttribute("tip", "ok");
model.addAttribute("filename",file_name);
model.addAttribute("filenameGBK",old_name);
model.addAttribute("filelength",Math.round(file.getSize()/1024.0));
return returnPage;
} catch (Exception e) {
System.out.println(e.getMessage());
model.addAttribute("tip", "no");
model.addAttribute("errorString", "后台服务器异常");
return returnPage;
}
}
}
package com.soft.demo.controller;
@Controller
public class LoginAction {
}
dingdan = new DingDan();
dingdan.setUser_id(me);
List<DingDan> mygoodsDingDans = (List<DingDan>) dingDanDao.listDingDans(dingdan);
for (DingDan gChe:mygoodsDingDans) {
mygoods_ids.add(gChe.getGoods_id());
}
mygoods_ids_clone.retainAll(othergoods_ids);//mygoods_ids变为交集
int a = mygoods_ids.size();
int b = 0;
othergoods_ids.removeAll(mygoods_ids);
othergoods_ids.addAll(mygoods_ids);
if(othergoods_ids.size() == 0) {
b = 1;
}else {
b = othergoods_ids.size();
}
return a/b*2;
}
double getSimilarWithUserByPinglun(int me,int otherUserId) {
Pinglun pinglun = new Pinglun();
pinglun.setUser_id(otherUserId);
List<Integer> mygoods_ids = new ArrayList<Integer>();
List<Integer> mygoods_ids_clone = new ArrayList<Integer>();
List<Integer> othergoods_ids = new ArrayList<Integer>();
List<Integer> othergoods_ids_clone = new ArrayList<Integer>();
List<Pinglun> otherUserPingluns = (List<Pinglun>) pinglunDao.listPingluns(pinglun);
for (Pinglun gChe:otherUserPingluns) {
othergoods_ids.add(gChe.getGoods_id());
othergoods_ids_clone.add(gChe.getGoods_id());
}
pinglun = new Pinglun();
pinglun.setUser_id(me);
List<Pinglun> mygoodsPingluns = (List<Pinglun>) pinglunDao.listPingluns(pinglun);
for (Pinglun gChe:mygoodsPingluns) {
mygoods_ids.add(gChe.getGoods_id());
}
mygoods_ids_clone.retainAll(othergoods_ids);//mygoods_ids变为交集
int a = mygoods_ids_clone.size();
int b = 0;
othergoods_ids.removeAll(mygoods_ids);
othergoods_ids.addAll(mygoods_ids);
* @return String
*/
@RequestMapping(value="admin/Admin_sendOrders.action",method=RequestMethod.GET)
public String sendOrders(Orders paramsOrders,
ModelMap model){
try {
//订单发货
adminManager.sendOrders(paramsOrders);
setSuccessTip("订单发货成功", "Admin_listOrderss.action",model);
} catch (Exception e) {
setErrorTip("订单发货异常", "Admin_listOrderss.action",model);
}
return "infoTip";
}
/**
* @Title: delOrderss
* @Description: 删除商品订单
* @return String
*/
@RequestMapping(value="admin/Admin_delOrderss.action")
public String delOrderss(Orders paramsOrders,
ModelMap model){
try {
//删除商品订单
adminManager.delOrderss(paramsOrders);
setSuccessTip("删除商品订单成功", "Admin_listOrderss.action",model);
} catch (Exception e) {
setErrorTip("删除商品订单异常", "Admin_listOrderss.action",model);
}
return "infoTip";
}
/**
* @Title: listOrdersDetails
* @Description: 查询商品订单明细
* @return String
*/
@RequestMapping(value="admin/Admin_listOrdersDetails.action")
public String listOrdersDetails(OrdersDetail paramsOrdersDetail,PaperUtil paperUtil,
ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
try {
if (paramsOrdersDetail==null) {
paramsOrdersDetail = new OrdersDetail();
}
//设置分页信息
public List<Uview> listUviews(Uview uview, int[] sum) {
if (sum != null) {
sum[0] = uviewDao.listUviewsCount(uview);
}
List<Uview> uviews = uviewDao.listUviews(uview);
return uviews;
}
/**
* @Title: queryUview
* @Description: 浏览记录查询
* @param uview
* @return Uview
*/
public Uview queryUview(Uview uview) {
Uview _uview = uviewDao.getUview(uview);
return _uview;
}
/**
* @Title: addUview
* @Description: 添加浏览记录
* @param uview
* @return void
*/
public void addUview(Uview uview) {
uviewDao.addUview(uview);
}
/**
* @Title: listGoodssSimilarity
* @Description: 根据协同过滤算法得出商品推荐
* @param goods
* @return List<Goods>
*/
public List<Goods> listGoodssSimilarity(HttpSession session){
List<Goods> recomLists = new ArrayList<>();
User userFront = (User)session.getAttribute("userFront");//当前用户
int uid = userFront.getUser_id();//当前用户ID
List<Goods> likeLists; //其他用户喜欢的商品列表
List<User> users = userDao.listUsers(new User()); //所有用户列表
List<Goods> goodss = goodsDao.listGoodss(new Goods()); //所有商品列表
int[][] curMatrix = new int[goodss.size()+5][goodss.size()+5]; //当前矩阵
int[][] comMatrix = new int[goodss.size()+5][goodss.size()+5]; //共现矩阵
int[] N = new int[goodss.size()+5]; //喜欢每个物品的人数
for(User user: users){
if(user.getUser_id()==uid) continue; //当前用户则跳过
likeLists = findLikesByUser(user.getUser_id()); //当前用户的喜欢列表
//查询用户名是否被占用
User user = new User();
user.setUser_name(params.getUser_name());
User user_temp = loginIndexManager.getUser(user);
if (user_temp!=null) {
jsonData.setErrorReason("注册失败,用户名已被注册:"+params.getUser_name());
return jsonData;
}
//添加用户入库
params.setUser_flag(1);
params.setReg_date(DateUtil.getCurDateTime());
loginIndexManager.addUser(params);
} catch (Exception e) {
jsonData.setErrorReason("注册异常,请稍后重试");
return jsonData;
}
return jsonData;
}
}
package com.soft.demo.controller;
@Controller
public class UploadAdminAction {
public static String path = "config.properties"; //保存数据库连接信息的属性文件的相对路径
public static Properties props = new Properties();
static{
if (ordersDetail.getGoods_id()==goods_id) {
card.remove(ordersDetail);
break;
}
}
}
httpSession.setAttribute("card", card);
}
/**
* @Title: clearCard
* @Description: 清空购物车
*/
public void clearCard(HttpSession httpSession) {
//清空购物车
httpSession.removeAttribute("card");
}
@SuppressWarnings("unchecked")
private OrdersDetail getGoodsFromCard(int goods_id,HttpSession httpSession) {
//查询购物车
List<OrdersDetail> card = (List<OrdersDetail>) httpSession.getAttribute("card");
if (card!=null) {
for (OrdersDetail ordersDetail : card) {
if (ordersDetail.getGoods_id()==goods_id) {
return ordersDetail;
}
}
}else {
return null;
}
return null;
}
/**
* @Title: addOrders
* @Description: 添加商品订单
* @param orders
* @return Orders
*/
@SuppressWarnings("unchecked")
public void addOrders(Orders orders,HttpSession httpSession) {
//生成订单号
String orders_no = DateUtil.dateToDateString(new Date(), "yyyyMMddHHmmss")+orders.getUser_id();
orders.setOrders_no(orders_no);
//订单日期
httpSession.removeAttribute("card");
}
/**
* @Title: listCard
* @Description: 查询购物车
* @return List<OrdersDetail>
*/
@SuppressWarnings("unchecked")
public List<OrdersDetail> listCard(HttpSession httpSession) {
//查询购物车
List<OrdersDetail> card = (List<OrdersDetail>) httpSession.getAttribute("card");
if (card==null) {
card = new ArrayList<OrdersDetail>();
}
return card;
}
/**
* @Title: listOrderss
* @Description: 商品订单查询
* @param orders
* @return List<Orders>
*/
public List<Orders> listOrderss(Orders orders,int[] sum){
if (sum!=null) {
sum[0] = ordersDao.listOrderssCount(orders);
}
List<Orders> orderss = ordersDao.listOrderss(orders);
return orderss;
}
/**
* @Title: queryOrders
* @Description: 商品订单查询
* @param orders
* @return Orders
*/