基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)
管理员:
admin 123456
用户:
13511111111 123456
13511111112 123456
13511111113 123456
@PostMapping("save.htm")
@ResponseBody
public Result savePage(Model model , ChildTypeEntity entity){
if(entity.getId()==null || entity.getId().equals("")){
entity.setId(IdWorker.get32UUID());
childTypeService.insert(entity);
}
return Result.success("用户保存成功");
}
}
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private UserDao userDao;
@Autowired
private RoleService roleService;
@Autowired
private UserService userService;
/**
@RequestMapping("regData.html")
@ResponseBody
public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
customerEntity.setId(IdWorkerUtil.getId());
customerEntity.setHeader("/img/a5.jpg");
customerService.insert(customerEntity);
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success(customerEntity.getId(),"登陆成功");
}
}
@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {
CustomerEntity customerEntity = Contants.getCustomer();
model.addAttribute("entity",customerEntity);
return "mobile/my_update";
}
/**
* 我的界面 -- 修改
* @return
* @throws Exception
*/
@RequestMapping("myUpdateData.do")
@ResponseBody
public Result myUpdateData( CustomerEntity customerEntity)throws Exception{
customerEntity.setId(Contants.getCustomer().getId());
customerService.updateById(customerEntity);
return Result.success("成功");
}
/**
* 登陆界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("login.html")
public String login(Model model) throws Exception{
return "mobile/login";
}
/**
* 退出登陆
* @return
* @throws Exception
*/
@RequestMapping("logOut.do")
@ResponseBody
public Result logOut( HttpServletResponse response)throws Exception{
Cookie cookie = new Cookie("login_key_auth_customer","-1");
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
return Result.success("退出成功");
}
/**
* 登陆
* @return
orderShopService.updateById(orderShopEntity);
orderShopEntity = orderShopService.selectById(orderShopEntity.getId());
Double num = orderShopDao.num(orderShopEntity.getShopId());
ShopEntity shopEntity = new ShopEntity();
shopEntity.setId(orderShopEntity.getShopId());
shopEntity.setScore(num);
shopService.updateById(shopEntity);
return Result.success(1);
}
/**
* 收货
* @param id
* @return
* @throws Exception
*/
@RequestMapping("shouhuo.do")
@ResponseBody
public Result shouhuo(String id)throws Exception{
OrderEntity orderEntity = orderService.selectById(id);
orderEntity.setStatus(3);
orderService.updateById(orderEntity);
return Result.success("欢迎下次光临");
}
/**
*
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model) throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq(OrderTable.CUSTOMER_ID,userEntity.getId()).orderBy("time",false);
List<OrderEntity> orders = orderService.selectList(wrapper);
if(orders!=null){
for (OrderEntity order : orders) {
wrapper = new EntityWrapper();
wrapper.eq("order_id",order.getId());
model.addAttribute("menuEntities",menuEntities);
model.addAttribute("roleId",id);
return "role/auth";
}
/**
* 权限分配
* @param ids
* @param model
* @return
* @throws Exception
*/
@RequestMapping("authData.htm")
@ResponseBody
@ImLog(type = "角色",mark = "角色分配权限 {id} {ids}")
public Result data(String[] ids,String roleId,Model model)throws Exception{
List<String> list = new ArrayList<>();
for (String id : ids) {
list.add(id);
}
List<MenuEntity> menuEntities = menuService.selectBatchIds(list);
//删除原有权限
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(RoleMenuTable.ROLE_ID,roleId);
roleMenuService.delete(entityWrapper);
Set<String> set = new HashSet<>();
//循环添加新的权限
for (MenuEntity menuEntity : menuEntities) {
set.add(menuEntity.getpId());
}
for (String s : set) {
RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
roleMenuEntity.setId(IdWorkerUtil.getId());
roleMenuEntity.setMenuId(s);
roleMenuEntity.setRoleId(roleId);
roleMenuService.insert(roleMenuEntity);
}
for (String s : list) {
RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
roleMenuEntity.setId(IdWorkerUtil.getId());
roleMenuEntity.setMenuId(s);
roleMenuEntity.setRoleId(roleId);
roleMenuService.insert(roleMenuEntity);
}
return Result.success("权限保存成功");
}
}
return "mobile/article/list";
}
/**
* 分页
* @return
* @throws Exception
*/
@GetMapping("page.do")
@ResponseBody
public PageVo page(String title, String summary,int page , int limit)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
if(!StringUtils.isEmpty(title)){
entityWrapper.like(ArticleTable.TITLE,title);
}
if(!StringUtils.isEmpty(summary)){
entityWrapper.like(ArticleTable.SUMMARY,summary);
}
entityWrapper.eq(ArticleTable.CUSTOMER_ID, Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
Page<ArticleEntity> paged = new Page();
paged.setSize(limit);
paged.setCurrent(page);
PageVo<ArticleEntity> pageVo = new PageVo<>();
pageVo.setCode(0);
pageVo.setCount(paged.getTotal());
pageVo.setPageNum(limit);
pageVo.setPageSize(page);
return pageVo;
}
/**
* 界面
* @return
* @throws Exception
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("addData.do")
@ResponseBody
public Result addDatax(ArticleEntity articleEntity, HttpSession session)throws Exception{
articleEntity.setId(IdWorkerUtil.getId());
articleEntity.setTime(new Date());
articleEntity.setStatus(0);
articleEntity.setCustomerId(Contants.getCustomer().getId());
articleEntity.setTop(false);
return Result.success("保存成功");
}
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("edit.do")
public String edit(String id, Model model )throws Exception{
List<ShopEntity> shopEntities = shopService.selectList(new EntityWrapper<>());
model.addAttribute("shopEntities",shopEntities);
return "mobile/article/edit";
}
}
/**
}
@PostMapping("list.do")
public Result list()throws Exception{
//首先查询帮助信息
EntityWrapper entityWrapper = new EntityWrapper();
//消息列表
entityWrapper
.eq("user_id", Contants.getCustomer().getId())
.orderBy("time",true);
List<ChatRoomEntity> list = chatRoomService.selectList(entityWrapper);
for (ChatRoomEntity chatRoomEntity : list) {
chatRoomEntity.setBr(chatRoomEntity.getSendUser().equals(Contants.getCustomer().getId()));
}
return Result.success(list);
}
/**
* 发送消息
* @param chatRoomEntity
* @return
*/
@RequestMapping("addContent.do")
public Result addContent(ChatRoomEntity chatRoomEntity){
//首先查询帮助信息
chatRoomEntity.setId(IdWorker.get32UUID());
chatRoomEntity.setRead(false);
chatRoomEntity.setSendUser(Contants.getCustomer().getId());
chatRoomEntity.setUserId(Contants.getCustomer().getId());
chatRoomEntity.setAssistUserId("-99");
chatRoomEntity.setTime(new Date());
chatRoomService.insert(chatRoomEntity);
return Result.success("发送成功");
}
}
private CustomerService customerService;
@Autowired
private ChildTypeService childTypeService;
@Autowired
private ShopService shopService;
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("list.do")
public String list(Model model)throws Exception{
return "mobile/article/list";
}
/**
* 分页
* @return
* @throws Exception
*/
@GetMapping("page.do")
@ResponseBody
public PageVo page(String title, String summary,int page , int limit)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
if(!StringUtils.isEmpty(title)){
entityWrapper.like(ArticleTable.TITLE,title);
}
if(!StringUtils.isEmpty(summary)){
entityWrapper.like(ArticleTable.SUMMARY,summary);
}
entityWrapper.eq(ArticleTable.CUSTOMER_ID, Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
Page<ArticleEntity> paged = new Page();
paged.setSize(limit);
paged.setCurrent(page);
PageVo<ArticleEntity> pageVo = new PageVo<>();
pageVo.setCode(0);
pageVo.setCount(paged.getTotal());
pageVo.setPageNum(limit);
pageVo.setPageSize(page);
return pageVo;
}
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
return Result.success("退出成功");
}
/**
* 登陆
* @return
* @throws Exception
*/
@RequestMapping("loginData.html")
@ResponseBody
public Result loginData(String phone,String password, HttpServletResponse response)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq("phone",phone);
CustomerEntity customerEntity = customerService.selectOne(entityWrapper);
if(customerEntity==null){
return Result.error("用户不存在");
}
if(!customerEntity.getPassword().equals(password)){
return Result.error("密码错误");
}
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success(customerEntity.getId(),"登陆成功");
}
/**
* 登陆界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("reg.html")
public String reg(Model model) throws Exception{
return "mobile/reg";
}
/**
* 登陆
* @return
* @throws Exception
*/
@RequestMapping("regData.html")
@ResponseBody
public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
customerEntity.setId(IdWorkerUtil.getId());
customerEntity.setHeader("/img/a5.jpg");
return "childType/save";
}
/**
* 保存
* @param model
* @return
*/
@PostMapping("save.htm")
@ResponseBody
public Result savePage(Model model , ChildTypeEntity entity){
if(entity.getId()==null || entity.getId().equals("")){
entity.setId(IdWorker.get32UUID());
childTypeService.insert(entity);
}
return Result.success("用户保存成功");
}
}
wrapper.eq(CustomerAddressTable.CUSTOMER_ID,customerEntity.getId());
List<CustomerAddressEntity> list = service.selectList(wrapper);
model.addAttribute("list",list);
return "mobile/address_list";
}
/**
* 保存界面
* @param model
* @param id
* @return
* @throws Exception
*/
@RequestMapping("save.do")
public String save(Model model,String id)throws Exception{
CustomerAddressEntity entity = new CustomerAddressEntity();
if(!StringUtils.isEmpty(id)){
entity = service.selectById(id);
}
model.addAttribute("entity",entity);
return "mobile/address_save";
}
/**
* 保存
* @param model
* @return
* @throws Exception
*/
@RequestMapping("saveData.do")
@ResponseBody
public Result save(Model model, CustomerAddressEntity entity)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
entity.setCustomerId(customerEntity.getId());
if(StringUtils.isEmpty(entity.getId())){
entity.setId(IdWorkerUtil.getId());
service.insert(entity);
}else{
service.updateById(entity);
return Result.success("用户保存成功");
}
}
@Controller
@RequestMapping("user")
public class UserController {
@Autowired
private UserDao userDao;
@Autowired
private RoleService roleService;
@Autowired
private UserService userService;
/**
* 用户界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.htm")
return true;
}
Cookie[] cookies = httpServletRequest.getCookies();
if(cookies==null || cookies.length==0){
throw new NeedLoginException("需要登录");
}
String uid = "";
for (Cookie cookie : cookies) {
if(cookie.getName().equals("login_key_auth")){
uid = cookie.getValue();
}
}
if(StringUtils.isEmpty(uid)){
throw new NeedLoginException("需要登录");
}
UserEntity userEntity = userService.selectById(uid);
if(userEntity==null || userEntity.getStatus()==false){
throw new NeedLoginException("需要登录");
}
Contants.USER_ENTITY_THREAD_LOCAL.set(userEntity);
Cookie cookie = new Cookie("login_key_auth",userEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
httpServletResponse.addCookie(cookie);
return true;
}
@Override
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
}
}
if(StringUtils.isEmpty(id)){
roleEntity.setId(IdWorker.get32UUID());
roleEntity.setTime(new Date());
roleService.insert(roleEntity);
}else{
roleEntity.setId(id);
roleService.updateById(roleEntity);
}
return Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.htm")
@ResponseBody
@ImLog(type = "角色",mark = "删除角色 {id}")
public Result del(String id)throws Exception{
roleService.deleteById(id);
return Result.success("保存成功");
}
/**
* 权限界面
* @return
* @throws Exception
*/
@RequestMapping("auth.htm")
public String auth(String id,Model model)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(RoleMenuTable.ROLE_ID,id);
List<RoleMenuEntity> entity = roleMenuService.selectList(entityWrapper);
List<MenuEntity> menuEntities = menuService.selectList(null);
if(entity!=null && !entity.isEmpty()){
Set<String> menuids = new HashSet<>();
for (RoleMenuEntity roleMenuEntity : entity) {
menuids.add(roleMenuEntity.getMenuId());
}
for (MenuEntity menuEntity : menuEntities) {
if(menuids.contains(menuEntity.getId())){
menuEntity.setAuth(true);
}
/**
*/
@Controller
@RequestMapping("file")
public class ImgController {
public static final String FILE_PATH = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\upload\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
//用来检测程序运行时间
String fileName = IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
try {
File file1 = new File(FILE_PATH+"\\"+fileName);
file1.createNewFile();
//获取输出流
OutputStream os=new FileOutputStream(file1.getPath());
//获取输入流 CommonsMultipartFile 中可以直接得到文件的流
InputStream is=file.getInputStream();
int temp;
//一个一个字节的读取并写入
while((temp=is.read())!=(-1))
{
/**
* 普通用户管理
*/
@Controller
@RequestMapping("childType")
public class ChildTypeController {
@Autowired
private ChildTypeService childTypeService ;
/**
* 根据1级分类查询2级分类
* @param type
* @return
*/
@PostMapping("childList.htm")
@ResponseBody
public Result childList(Integer type){
EntityWrapper entityWrapper = new EntityWrapper();
List<ChildTypeEntity> list = childTypeService.selectList(entityWrapper);
return Result.success(list);
}
/**
* 根据1级分类查询2级分类
* @param type
* @return
*/
@PostMapping("childList.do")
@ResponseBody
public Result childListdo(Integer type){
EntityWrapper entityWrapper = new EntityWrapper();
List<ChildTypeEntity> list = childTypeService.selectList(entityWrapper);
return Result.success(list);
}
/**