ssm商城系统(爱淘淘购物)项目演示
本系统采用SSM架构来搭建。
服务器:tomcat7
java虚拟机:jdk1.7
数据库:mysql
前端:Vue + Bootstrap
管理员用户:root root
普通用户:jack 123
访问路径:
http://localhost:8080/app/index.jsp
http://localhost:8080/app/login.jsp
注意点:商品名字不要太长,价格不要用小数,用整数。
可用于毕业设计,课程设计,应急用。基本的商品增删改查,上传商品等逻辑都是有的,具体可以看演示视频~~
源码下载:
链接:https://pan.baidu.com/s/1GV7TR4sphunYVEMMp-TU0Q
提取码:1234
UserController.java
package com.tz.web.admin;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tz.bean.TblSysUser;
import com.tz.bean.TblSysUserExample;
import com.tz.core.CommonVo;
import com.tz.core.ProcessException;
import com.tz.dao.TblSysMenuMapper;
import com.tz.dao.TblSysUserMapper;
import com.tz.util.ResponseUtil;
import com.tz.util.TmStringUtils;
import net.sf.json.JSONObject;
@Controller
public class UserController extends BaseController{
@Autowired
TblSysUserMapper tblSysUserMapper;
@Autowired
TblSysMenuMapper tblSysMenuMapper;
@RequestMapping("/getTblSysUserById")
@ResponseBody
public JSONObject getTblSysUserById(Integer id,HttpServletRequest request){
com.tz.bean.TblSysUser selectByPrimaryKey = tblSysUserMapper.selectByPrimaryKey(id);
vo.setData(selectByPrimaryKey);
return JSONObject.fromObject(vo);
}
@RequestMapping("/deleteUser")
@ResponseBody
public JSONObject deleteUser(Integer id,HttpServletRequest request) throws Exception{
try{
tblSysUserMapper.deleteByPrimaryKey(id);
}catch(Exception e){
throw new ProcessException("系统故障,请联系管理员!");
}
return JSONObject.fromObject(vo) ;
}
@RequestMapping("/getUserList")
@ResponseBody
public JSONObject getUserList(String userName,HttpServletRequest request) throws Exception{
TblSysUserExample tblSysUserExample = new TblSysUserExample();
tblSysUserExample.createCriteria().andUserNameLike("%"+userName+"%");
tblSysUserExample.setOrderByClause("create_time desc");
List<TblSysUser> list = tblSysUserMapper.selectByExample(tblSysUserExample);
vo.setList(list);
return JSONObject.fromObject(vo) ;
}
@RequestMapping("/register")
@ResponseBody
public TblSysUser TblSysUser(TblSysUser user) throws Exception{
//检查用户名是否重复
TblSysUser tblSysUserByUserName = commonService.getTblSysUserByUserName(user.getUserName());
if(tblSysUserByUserName != null){
throw new ProcessException("用户名重复");
}
user.setRoleId(1); //默认角色1,测试用
System.out.println(TmStringUtils.getNow());
user.setCreateTime(TmStringUtils.getNow());
int i = tblSysUserMapper.insert(user);
return null;
}
@RequestMapping("/userAdd")
@ResponseBody
public CommonVo userAdd(TblSysUser user) throws Exception{
//检查用户名是否重复
TblSysUser tblSysUserByUserName = commonService.getTblSysUserByUserName(user.getUserName());
if(tblSysUserByUserName != null){
throw new ProcessException("用户名重复");
}
user.setRoleId(1); //默认角色1,测试用
user.setCreateTime(TmStringUtils.getNow());
int i = tblSysUserMapper.insert(user);
return vo;
}
@RequestMapping("/userEdit")
@ResponseBody
public CommonVo userEdit(TblSysUser user) throws Exception{
tblSysUserMapper.updateByPrimaryKeySelective(user);
return vo;
}
@RequestMapping("/login")
@ResponseBody
public TblSysUser login(TblSysUser user,HttpServletRequest request,HttpServletResponse response) throws Exception{
TblSysUser tblSysUserByUserName = commonService.getTblSysUserByUserName(user.getUserName());
if(tblSysUserByUserName == null){
throw new ProcessException("用户名不存在");
}
TblSysUser tblSysUser = commonService.getTblSysUserByUserNamePassword(user);
if(tblSysUser == null){
throw new ProcessException("用户名或者密码错误");
}
request.getSession().setAttribute("loginUser", tblSysUser);
if(tblSysUser.getRoleId() == 1){
vo.setData(tblSysUser);
ResponseUtil.write(JSONObject.fromObject(vo), response);
return null;
}
//查询该用户所拥有的所有菜单
List<Map<String, Object>> menus = tblSysUserMapper.getMenus(tblSysUser.getId());
String MENUS = (String) menus.get(0).get("MENUS");
List<Map<String, Object>> menusList = tblSysUserMapper.getMenusList(MENUS);
request.getSession().setAttribute("menusList", menusList);
vo.setData(tblSysUser);
ResponseUtil.write(JSONObject.fromObject(vo), response);
return null;
}
@RequestMapping("/getAuth")
@ResponseBody
public JSONObject getAuth(HttpServletRequest request) throws Exception{
List menusList = (List) request.getSession().getAttribute("menusList");
if(menusList == null){
throw new ProcessException("用户尚未登录!");
}
//获取当前的用户角色
TblSysUser tblSysUser = (com.tz.bean.TblSysUser) request.getSession().getAttribute("loginUser");
vo.setData(tblSysUser.getRoleId());
vo.setList(menusList);
return JSONObject.fromObject(vo) ;
}
}