Table of Contents
Project Introduction
Environment requirements
Technology stack
Usage Instructions
Rendering display
Home Java javaTutorial How to implement flower mall system in Java

How to implement flower mall system in Java

May 17, 2023 am 11:31 AM
java

Project Introduction

This project is a front-end and back-end project, divided into two roles: ordinary users and administrators. Ordinary users log in at the front desk and administrators log in at the backend;

Administrator roles include the following Functions:

Administrator login, user management, flower category management, flower management, order management and delivery, message management, system announcement management and other functions.

User roles include the following functions:

The website provides user homepage, user registration and login, flower details view, product addition to shopping cart, order confirmation, personal order view, mall message board and mall announcements and many other functions.

Environment requirements

1. Running environment: preferably java jdk 1.8, we run on this platform. Other versions are theoretically possible.

2. IDE environment: IDEA, Eclipse, Myeclipse are all available. Recommended IDEA;

3. Tomcat environment: Tomcat 7.x, 8.x, 9.x versions are available

4. Hardware environment: windows 7/8/10 1G memory or more; Or Mac OS;

5. Database: MySql version 5.7;

6. Whether it is a Maven project: No;

Technology stack

1. Backend :Spring SpringMVC Mybatis

2. Front-end: JSP jQuery Ajax

Usage Instructions

1. Use Navicat or other tools to create a database with the corresponding name in mysql and import it The sql file of the project;

2. Use IDEA/Eclipse/MyEclipse to import the project. When importing into Eclipse/MyEclipse, if it is a maven project, please select maven; if it is a maven project, please execute maven clean after the import is successful; maven install command, and then run;

3. Change the database configuration in the jdbc.properties configuration file in the project to your own configuration;

4. Run the project and enter localhost:8080/ to log in

User account/password: user/123456

Administrator account/password: admin/admin

Rendering display

How to implement flower mall system in Java

How to implement flower mall system in Java

How to implement flower mall system in Java

How to implement flower mall system in Java

How to implement flower mall system in Java

How to implement flower mall system in Java

##Core Code

Commodity Management Control Layer

/**
 * 商品
 **/
@RestController
@RequestMapping("flower")
public class FlowerController {
    @Autowired
    FlowersService flowerService;
 
    @Autowired
    FlowersDao flowersDao;
 
    @RequestMapping("/test")
    R test() {
        R r = new R();
        return r;
    }
 
    //find
    @RequestMapping("/find")
    R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey, @RequestParam("searchType") String searchType) {
        R r = new R();
        List<Flower> flowers = flowerService.find(searchKey, searchType);
        if (flowers == null) {
            return r.setCode(2000);
        }
        return getResponse(flowers, page, Constant.SHOW_PAGE_SIZE, r);
    }
 
    // 管理员查询所有
    @RequestMapping("/findAll")
    R findAll(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
        R r = new R();
        List<Flower> flowers = flowerService.findAll(searchKey);
        if (flowers == null) {
            return r.setCode(2000);
        }
        return getResponse(flowers, page, Constant.PAGE_SIZE, r);
    }
 
    // 返回结果
    private R getResponse(List<Flower> flowers, int page, int pageSize, R r) {
        Map<String, Object> map = new HashMap<>();
        List<Flower> items = flowers.size() >= page * pageSize ?
                flowers.subList((page - 1) * pageSize, page * pageSize)
                : flowers.subList((page - 1) * pageSize, flowers.size());
        int len = flowers.size() % pageSize == 0 ? flowers.size() / pageSize
                : (flowers.size() / pageSize + 1);
        for (Flower item : items) {
            if (item.getImg_guid() == null) {
                item.setImg_guid(Constant.DEFAULT_IMG);
            }
            item.setImg_guid(Constant.IMG_USE_PATH + item.getImg_guid());
        }
        map.put("items", items);
        map.put("len", len);
        return r.setCode(2000).setData(map);
    }
 
    @RequestMapping("/create")
    R create(@RequestBody Flower flower) {
        R r = new R();
        int ans = flowerService.add(flower);
        if (ans == 1) {
            return r.setCode(2000).setMsg(HttpMsg.ADD_FLOWER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.ADD_FLOWER_FAILED);
    }
 
    @RequestMapping("/update")
    R update(@RequestBody Flower flower) {
        R r = new R();
        int ans = flowerService.update(flower);
        if (ans >= 0) {
            return r.setCode(2000).setMsg(HttpMsg.UPDATE_FLOWER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.UPDATE_FLOWER_FAILED);
    }
 
    @RequestMapping("/changeState")
    R changeState(@RequestBody Flower flower) {
        R r = new R();
        flowersDao.changeState(flower);
        String msg = flower.getState() == 1?HttpMsg.GOODS_UP_OK:HttpMsg.GOODS_DOWN_OK;
        return r.setCode(2000).setMsg(msg);
    }
 
    // 保存上传的图片
    @RequestMapping("/updateImg")
    R updateImg(@RequestParam("file") MultipartFile file) {
        R r = new R();
        // 只接收 jpg/png 图片
        String filename = file.getOriginalFilename();
        if (!filename.endsWith(".jpg") && !filename.endsWith(".png")){
            return r.setCode(4000).setMsg(HttpMsg.ERROR_FILE_TYPE);
        }
        String img_guid = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
        try {
            savePic(file.getInputStream(), img_guid);
            return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK).setData(img_guid);
        } catch (IOException e) {
            return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED);
        }
    }
 
    @PutMapping("/updateImgGuid")
    R updateImgGuid(@RequestParam("guid") String guid, @RequestParam("id") int id) {
        R r = new R();
        int ans = flowerService.updateImg(guid, id);
        if (ans == 1) {
            return r.setCode(2000).setMsg(HttpMsg.UPDATE_PIC_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.UPDATE_PIC_FAILED);
    }
 
    @DeleteMapping("/delete")
    R delete(@RequestParam("id") int id) {
        R r = new R();
        int ans = flowerService.delete(id);
        if (ans == 1) {
            return r.setCode(2000).setMsg(HttpMsg.DELETE_FLOWER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.DELETE_FLOWER_FAILED);
    }
 
    private void savePic(InputStream inputStream, String fileName) {
        OutputStream os = null;
        try {
            String path = Constant.IMG_PATH;
            // 1K的数据缓冲
            byte[] bs = new byte[1024];
            // 读取到的数据长度
            int len;
            // 输出的文件流保存到本地文件
            os = new FileOutputStream(new File(path + fileName));
            // 开始读取
            while ((len = inputStream.read(bs)) != -1) {
                os.write(bs, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 完毕,关闭所有链接
            try {
                os.close();
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Copy after login

Order Management Control Layer

/**
 * 用户
 **/
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    UserDao userDao;
    @Autowired
    OrderDao orderDao;
    @Autowired
    FlowersDao flowersDao;
 
    @RequestMapping("/test")
    R test() {
        R r = new R();
        return r.setCode(4000).setMsg(Constant.IMG_PATH).setData(orderDao.findAll(null));
    }
 
    @RequestMapping("/queryByAccount")
    R queryByAccount(@RequestParam("account") String account) {
        R r = new R();
        if (StringUtil.isEmpty(account)) {
            return r.setCode(4000).setMsg(HttpMsg.INVALID_PARAM);
        }
        List<Order> orders = orderService.queryByAccount(account);
        return r.setCode(2000).setData(orders);
    }
 
    @RequestMapping("/find")
    R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey, @RequestParam("account") String account) {
        R r = new R();
        Map<String, Object> map = new HashMap<>();
        List<Order> orders = orderService.find(searchKey, account);
        if (orders == null) {
            return r.setCode(2000);
        }
        map.put("items", orders);
        map.put("len", orders.size());
        return r.setCode(2000).setData(map);
    }
 
    @RequestMapping("/findAll")
    R findAll(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
        R r = new R();
        Map<String, Object> map = new HashMap<>();
        List<Order> orders = orderService.findAll(searchKey);
        if (orders == null) {
            return r.setCode(2000);
        }
        List<Order> items = orders.size() >= page * Constant.PAGE_SIZE ?
                orders.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
                : orders.subList((page - 1) * Constant.PAGE_SIZE, orders.size());
        int len = orders.size() % Constant.PAGE_SIZE == 0 ? orders.size() / Constant.PAGE_SIZE
                : (orders.size() / Constant.PAGE_SIZE + 1);
        List<OrderVo> vos = new ArrayList<>();
        for (Order item : items) {
            User user = userDao.queryById(item.getUid());
            OrderVo vo = new OrderVo();
            vo.setAddress(user.getAddress()).setPhone(user.getPhone()).setUsername(user.getName())
                    .setAmount(item.getAmount()).setFlower(item.getFlower()).setId(item.getId())
                    .setUid(item.getUid()).setOrder_guid(item.getOrder_guid()).setPrice(item.getPrice())
                    .setState(item.getState());
            vos.add(vo);
        }
        map.put("items", vos);
        map.put("len", len);
        return r.setCode(2000).setData(map);
    }
 
    @RequestMapping("/update")
    R update(@RequestBody Order order) {
        R r = new R();
        int ans = orderService.update(order);
        if (ans >= 0) {
            return r.setCode(2000).setMsg(HttpMsg.UPDATE_USER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.UPDATE_USER_FAILED);
    }
 
    @RequestMapping("/changeState")
    R changeState(@RequestBody Order order) {
        orderDao.changeState(order);
        return new R().setCode(2000).setMsg(HttpMsg.UPDATE_ORDER_OK);
    }
 
    @DeleteMapping("/delete")
    R delete(@RequestParam("id") int id) {
        R r = new R();
        int ans = orderService.delete(id);
        if (ans == 1) {
            return r.setCode(2000).setMsg(HttpMsg.DELETE_USER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.DELETE_USER_FAILED);
    }
}
Copy after login

User Management Control Layer

/**
 * 用户
 **/
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    UserDao dao;
 
    @RequestMapping("/test")
    R test() {
        R r = new R();
        return r.setCode(4000).setMsg(Constant.IMG_PATH).setData(dao.findAll());
    }
 
    @RequestMapping("/queryInfoByAccount")
    R queryInfoByAccount(@RequestParam("account") String account) {
        R r = new R();
        if (StringUtil.isEmpty(account)){
            return r.setCode(4000).setMsg(HttpMsg.INVALID_PARAM);
        }
        User loginUser = userService.queryInfo(account);
        if (loginUser == null){
            return r.setCode(4000).setMsg(HttpMsg.INVALID_USER);
        }
        return r.setCode(2000).setData(loginUser);
    }
 
 
    @RequestMapping("/find")
    R find(@RequestParam("page") int page, @RequestParam("searchKey") String searchKey) {
        R r = new R();
        Map<String, Object> map = new HashMap<>();
        List<User> users = userService.find(searchKey);
        if (users == null) {
            return r.setCode(2000);
        }
        List<User> items = users.size() >= page * Constant.PAGE_SIZE ?
                users.subList((page - 1) * Constant.PAGE_SIZE, page * Constant.PAGE_SIZE)
                : users.subList((page - 1) * Constant.PAGE_SIZE, users.size());
        int len = users.size() % Constant.PAGE_SIZE == 0 ? users.size() / Constant.PAGE_SIZE
                : (users.size() / Constant.PAGE_SIZE + 1);
        map.put("items", items);
        map.put("len", len);
        return r.setCode(2000).setData(map);
    }
 
 
    @RequestMapping("/create")
    R create(@RequestBody User user) {
        R r = new R();
        int ans = userService.add(user);
        if (ans == 1) {
            return r.setCode(2000).setMsg(HttpMsg.ADD_USER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.ADD_USER_FAILED);
    }
 
    @RequestMapping("/update")
    R update(@RequestBody User user) {
        R r = new R();
        int ans = userService.update(user);
        if (ans >= 0) {
            return r.setCode(2000).setMsg(HttpMsg.UPDATE_USER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.UPDATE_USER_FAILED);
    }
 
 
    @DeleteMapping("/delete")
    R delete(@RequestParam("id") int id) {
        R r = new R();
        int ans = userService.delete(id);
        if (ans == 1) {
            return r.setCode(2000).setMsg(HttpMsg.DELETE_USER_OK);
        }
        return r.setCode(4000).setMsg(HttpMsg.DELETE_USER_FAILED);
    }
}
Copy after login

The above is the detailed content of How to implement flower mall system in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Java Program to Find the Volume of Capsule Java Program to Find the Volume of Capsule Feb 07, 2025 am 11:37 AM

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4

PHP vs. Python: Core Features and Functionality PHP vs. Python: Core Features and Functionality Apr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles