Java project: tea traceability system (java+SSM+JSP+bootstrap+layUI+mysql)

Source code acquisition: download from the blog homepage “resources”!

Project Introduction

The tea traceability system is divided into foreground and background. Ordinary users can check the sales history of tea through the 18-digit code at the front desk.

The background is divided into two roles, administrator and dealer;

The main functions of the administrator include:

Main interface;

Administrator management: administrator list, add administrator;

Classification management: adding, deleting and modifying tea types;

Tea management: tea list, add, delete, modify tea;

Large package management: large package list, add, delete, modify large package;

Single product management: sales statistics, single product information modification;

The main functions of the dealer include:

Main interface;

Sold single product: confirm sold single product;

Environmental requirements

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

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

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

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

5. Maven project: No; check whether pom.xml is included in the source code directory; if it is included, it is a maven project, otherwise it is a non-maven project

6. Database: MySql version 5.7;

Technology stack

1. Backend: Spring Spring MVC MyBatis

2. Front end: JSP + bootstrap + jQuery + layUI

Instructions

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

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

3. Use IDEA/Eclipse/MyEclipse to import the project. When importing Eclipse/MyEclipse, if it is a maven project, please select maven;

If it is a maven project, after the import is successful, please execute the maven clean;maven install command, configure tomcat, and then run;

4. Run the project, enter localhost:8080/tea-web/ to log in

Administrator account control layer:

/**
 * (AdminAcct) table control layer
 *Administrator account
 */@CrossOrigin@RestController@RequestMapping("admin") publicclassAdminAcctController {
    /**
     * Service object
     */@Resourceprivate AdminAcctService adminAcctService;
    @Resourceprivate LicService licService;
    @Resourceprivate EntService entService;
    @Resourceprivate TypeTblService typeTblService;
    /**
     * Query a single piece of data by primary key
     *
     * @param id primary key
     * @return single data
     */public AdminAcct selectOne(Integer id) {
        return this.adminAcctService.queryById(id);
    }
    /**
     * Query the specified row data
     *
     * @param offset query starting position
     * @param limit query number
     * @return object list
     */public List<AdminAcct> queryAllByLimit(@Param("offset")int offset, @Param("limit")int limit) {
        return this.adminAcctService.queryAllByLimit(offset, limit);
    }
    /**
     * Delete data by primary key
     *
     * @param id primary key
     * @return success
     */public booleandeleteById(Integer id) {
        return this.adminAcctService.deleteById(id);
    }
    /**
     * change the data
     */public AdminAcct update(Integer id,String username,String pwd) {
        AdminAcct adminAcct=newAdminAcct();
        adminAcct. setId(id);
        adminAcct. setUsername(username);
        adminAcct.setPwd(pwd);
        return this.adminAcctService.update(adminAcct);
    }
    //log in Register/**
     * Log in
     *
     * @param username username
     * @param password password
     * @return Result object
     */@GetMapping( "login") public Result login(String username, String password) {
        BCryptPasswordEncoder bCryptPasswordEncoder=newBCryptPasswordEncoder();
        Result result=newResult();
        result. setSuccess(false);
        result. setDetail(null);
        if (username==null||username=="")
        {
            result.setMsg("User name cannot be empty");
            System.out.println("User name cannot be empty");
            return result;
        }
        if(password==""||password==null)
        {
            result.setMsg("The password cannot be empty");
            System.out.println("The password cannot be empty");
            return result;

        }
        AdminAcct temp=newAdminAcct();
        temp=this.adminAcctService.queryByUserName(username);
        if(temp==null) {
            System.out.println("Username does not exist");
            result.setMsg("Username does not exist");
            return result;
        }
        System.out.println(bCryptPasswordEncoder.encode(password));
        boolean flag=bCryptPasswordEncoder. matches(password, temp. getPwd());
        if(flag)
        {
            temp.setPwd("");
            System.out.println("Successful login");
            result.setMsg("Login successful");
            result. setSuccess(true);
            if(temp. getToken()==null)
            {
                Stringuuid= UUID.randomUUID().toString().replaceAll("-","");
                temp.setToken(uuid);
                this.adminAcctService.update(temp);
            }
            result. setDetail(temp);
            return result;
        }
        else
        {
            result.setMsg("Password error");
            System.out.println("Password error");
            return result;
        }
    }
    /**
     * register
     *
     * @param username username
     * @param password password
     * @return Result object
     */@PostMapping("register") public Result register(String username,String password) {
        BCryptPasswordEncoder bCryptPasswordEncoder=newBCryptPasswordEncoder();
        Result result=newResult();
        AdminAcct temp=newAdminAcct();
        result. setSuccess(false);
        result. setDetail(null);
        temp=this.adminAcctService.queryByUserName(username);
        if (username==null||username=="")
        {
            result.setMsg("User name cannot be empty");
            System.out.println("User name cannot be empty");
            return result;
        }
        if (temp!=null)
        {
            result.setMsg("User name is repeated");
            System.out.println("User name is repeated");
            return result;
        }
        temp=newAdminAcct();
        temp.setUsername(username);
        password=bCryptPasswordEncoder.encode(password);
        temp.setPwd(password);
        Stringuuid= UUID.randomUUID().toString().replaceAll("-","");
        temp.setToken(uuid);
        this.adminAcctService.insert(temp);
        temp.setPwd("");
        result. setDetail(temp);
        result.setMsg("Successful registration");
        result. setSuccess(true);
        System.out.println("Successful registration");
        return result;
    }
    //Filing review related/**
     * Output pending review list
     * @param id primary key
     * @return
     */public Result licOfAudit_list(Integer id){
        Result result=newResult();
        result. setSuccess(false);
        if(adminAcctService. queryById(id)==null){
            result.setMsg("enterprise id error");
            return result;
        }
        result.setDetail(licService.getModelByState(0));
        result. setSuccess(true);
        result.setMsg("Certificate to be audited successfully obtained");
        return result;
    }
    /**
     *
     * @param lid
     * @param state
     * @return
     *//**
     * Audit certificate
     * @param lid certificate id
     * @param state certificate status
     * @return
     */@PostMapping("setLicState") public Result SetLicState(Integer lid,Integer state){
        Result result=newResult();
        result. setSuccess(false);
        if(lid==null){
            result.setMsg("lid cannot be empty");
            return result;
        }
        Lic lic=licService.queryById(lid);
        if(lic==null){
            result.setMsg("certificate id error");
            return result;
        }
        result. setSuccess(true);
        result.setMsg("Certificate passed successfully");
        lic.setLicState(state);
        result.setDetail(licService.update(lic));
        return result;
    }
    /**
     * Certificate screening
     * @param ename business name
     * @param lictype certificate type
     * @param sernum number
     * @return
     */@Transactional(readOnly = true)@GetMapping("licList")public Result Lic_Screen(String ename, Integer lictype, String sernum,Integer licstate){
        Result result=newResult();
        result. setSuccess(false);
        List<Ent> list=newArrayList<Ent>();
        if(ename!=null){
            list=entService.queryByEName(ename);
        if(list.isEmpty()){
            result.setMsg("There is no similar enterprise with this enterprise name");
            System.out.println("Company name error");
            return result;
        }
        }
        if (lictype!=null & amp; & amp;typeTblService.queryById(lictype)==null){
            result.setMsg("enterprise type error");
            System.out.println("enterprise type error");
            return result;
        }
        List<LicModel> list_lic=newArrayList<LicModel>();
        if(!list.isEmpty()){
            Iterator<Ent> iterator=list. listIterator();
        while (iterator. hasNext()) {
            Liclic = newLic();
            lic.setEid(((Ent)iterator.next()).getEid());
            lic.setLicType(lictype);
            lic.setSerNum(sernum);
            lic.setLicState(licstate);
            List<LicModel> temp=licService. queryAllModel(lic);
            list_lic.addAll(temp);
        }
        }
        else {
            Liclic = newLic();
            lic.setLicType(lictype);
            lic.setSerNum(sernum);
            lic.setLicState(licstate);
            list_lic=licService.queryAllModel(lic);
        }
        if(list_lic.isEmpty()){
            result.setMsg("No such certificate");
            return result;
        }
        result.setMsg("Filtered successfully");
        result. setSuccess(true);
        result. setDetail(list_lic);
        return result;
    }

    /**
     * delete certificate
     * @param lid certificate number
     * @return Result
     */@PostMapping("licdelete") public Result Lic_Delete(Integer lid){
        Result result=newResult();
        result. setSuccess(false);

        if(licService. deleteById(lid)) {
            result. setSuccess(true);
            result.setMsg("Delete successfully");
            return result;
        }
        else {
            result.setMsg("Delete failed, the certificate does not exist");
            return result;
        }
    }
    /**@PostMapping("")
    public Result lic_Pass(Integer lid){
        Result result = new Result();
        result. setSuccess(false);
        Lic lic=licService.queryById(lid);
        if(lic==null){
            result.setMsg("certificate id error");
            return result;
        }
        result. setSuccess(true);
        result.setMsg("Certificate passed successfully");
        lic.setLicState((short)1);
        result.setDetail(licService.update(lic));
        return result;
    }
    @PostMapping("LicNoPass")
    public Result lic_NoPass(Integer lid){
        Result result = new Result();
        result. setSuccess(false);
        Lic lic=licService.queryById(lid);
        if(lic==null){
            result.setMsg("certificate id error");
            return result;
        }
        result. setSuccess(true);
        result.setMsg("Certificate failed successfully");
        lic.setLicState((short)2);
        result.setDetail(licService.update(lic));
        return result;
    }
     *///Company information related/**
     * Enterprise information screening
     * @param username username
     * @param ename business name
     * @param etype enterprise type
     * @param tel phone
     * @param email mailbox
     * @return
     */@GetMapping("userList") public Result Account_Screen(String username,String ename,Integer etype,String tel,String email){
        Result result=newResult();
        result. setSuccess(false);
        StringregEx="^([a-zA-Z0-9._%-] + @[a-zA-Z0-9.-] + \.[a-zA-Z]{2,4} )*$";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher;
        /**if(email!=null) {
            //Email format verification
            matcher = pattern. matcher(email);
            if (!matcher. matches()) {
                result.setMsg("Email format error");
                System.out.println("Mailbox format error");
                return result;
            }
        }*///Username format verification/**regEx="-^[\w\d_]{4,16}$";
        pattern=Pattern.compile(regEx);
        if(username!=null){
            matcher = pattern. matcher(username);
            if(!matcher. matches()){
            result.setMsg("Username format error");
            System.out.println("Username format error");
            return result;
            }
        }*/if (etype!=null & amp; & amp;typeTblService.queryById(etype)==null){
            result.setMsg("enterprise type error");
            System.out.println("enterprise type error");
            return result;
        }
        Ent ent = newEnt();
        ent.setTel(tel);
        ent.setUsername(username);
        ent.setEname(ename);
        ent.setEmail(email);
        ent.setEtype(etype);
        List list=entService. queryAll(ent);
        if (list.isEmpty()){
            result.setMsg("No such information");
            return result;
        }
        result.setDetail(entService.queryAll(ent));
        result. setSuccess(true);
        result.setMsg("Filtered successfully");
        return result;
    }
    /**
     * Modify enterprise information
     * @param eid enterprise id
     * @param etype enterprise type
     * @param tele phone
     * @param ename business name
     * @param email mailbox
     * @return
     */@PostMapping("editEntDetail") public Result EditEnt(Integer eid,Integer etype,String tele,String ename,String email){
        //Email format validation
        Result result=newResult();
        result. setSuccess(false);
        String regEx="^([a-zA-Z0-9._%-] + @[a-zA-Z0-9.-] + \.[a-zA-Z]{2,4 })*$";
        Pattern pattern=Pattern.compile(regEx);
        Matcher matcher;
        if(email!=null) {
            matcher = pattern. matcher(email);
            if (!matcher. matches()) {
                result.setMsg("Email format error");
                System.out.println("Mailbox format error");
                return result;
            }
        }
        Ent ent = newEnt();
        ent.setEid(eid);
        ent.setEtype(etype);
        ent.setTel(tele);
        ent.setEname(ename);
        result. setSuccess(true);
        result.setMsg("Modified successfully");
        ent=entService.update(ent);
        ent.setPwd("");
        result. setDetail(ent);
        return result;
    }
    /**
     *Reset enterprise account token
     * @param eid enterprise id
     * @return
     */@PostMapping("resetEntToken") public Result ResetEntToken(Integer eid){
        Result result=newResult();
        result. setSuccess(false);
        if(eid==null){
            result.setMsg("eid cannot be empty");
            return result;
        }
        if(entService. queryById(eid)==null){
            result.setMsg("eid error");
            return result;
        }
        Ent ent=entService.queryById(eid);
        String token=UUID.randomUUID().toString().replaceAll("-","");
        ent.setToken(token);
        ent=entService.update(ent);
        result.setMsg("reset token successful");
        result. setSuccess(true);
        result. setDetail(ent);
        return result;
    }

}

Product Management Control Layer:

/**
 * (Product) table control layer
 *
 */@RestController@RequestMapping("product") publicclassProductController {
    /**
     * Service object
     */@Resourceprivate ProductService productService;
    @Resourceprivate ProcessController processController;
    /**
     * Query a single piece of data by primary key
     *
     * @param pid primary key
     * @return single data
     */@GetMapping("selectOne") public Product selectOne(Integer pid) {
        return this.productService.queryById(pid);
    }
    /**
     * New data
     *///http://127.0.0.1:11451/product/insertOne?pid=1 &type=5001001 &weight=3.5 &ptime=2016-12-12 &lastOid=1& amp;state=1// @GetMapping("insertOne")// public Product insert(Integer pid, Integer type, Double weight, String ptime,Integer lastOid,Short state) {// Product product=new Product() ;// product.setPid(pid);// product.setType(type);// product.setWeight(weight);// product.setPtime(ptime);// product.setLastOid(lastOid);// product. setState(state);// return this.productService.insert(product);// }/**
     * update data
     *
     *///http://127.0.0.1:11451/product/updateOne?pid=1 & amp;bid=2@GetMapping("updateOne") public Product update(Integer pid, Integer type, Double weight, String ptime, Integer lastOid, Short state) {
        Product product=newProduct();
        product.setPid(pid);
        product.setType(type);
        product.setWeight(weight);
        product.setPtime(ptime);
        product.setLastOid(lastOid);
        product.setState(state);
        return productService. update(product);
    }
    /**
     * delete data
     *///http://127.0.0.1:11451/product/deleteOne?pid=2@GetMapping("deleteOne") public booleandeleteById(Integer pid) {
        return productService.deleteById(pid);
    }
    /**
     * Insert new data
     *
     * @param type meat type
     * @param weight weight
     * @param time processing time
     * @param lastoid last order number
     * @param state state
     * @param bid slaughter id
     * @param aid livestock id
     * @return single data
     */@GetMapping("insert") public Result insert(Integer type, Double weight, String time, Integer lastoid, short state, Integer bid, Integer aid) {
        Result result=newResult();
        result. setSuccess(false);
        result. setDetail(null);
        Product product=newProduct();
        SimpleDateFormatformat=newSimpleDateFormat("yyyy-MM-dd");
        try {
            // Set lenient to false. Otherwise, SimpleDateFormat will verify the date more loosely, for example, 2007/02/29 will be accepted and converted to 2007/03/01
            format. setLenient(false);
            format. parse(time);
        } catch (ParseException e) {
            System.out.println("Time input format error");
            e.printStackTrace();
            result.setMsg("The time is not entered according to the format");
            return result;
            // e.printStackTrace();// If throw java.text.ParseException or NullPointerException, it means the format is wrong
        }
        product.setLastOid(lastoid);
        product.setPtime(time);
        product.setState(state);
        product.setType(type);
        product.setWeight(weight);
        product=productService.insert(product);
        this.processController.insert(bid,aid,product.getPid());
        result.setMsg("Processing completed");
        result. setDetail(product);
        result. setSuccess(true);
        return result;
    }

}

Type management control layer:

/**
 * (TypeTbl) table control layer
 *
 */@RestController@RequestMapping("typeTbl") publicclassTypeTblController {
    /**
     * Service object
     */@Resourceprivate TypeTblService typeTblService;

    /**
     * Query a single piece of data by primary key
     *
     * @param tid primary key
     * @return single data
     */@GetMapping("selectOne") public TypeTbl selectOne(Integer tid) {
        return this.typeTblService.queryById(tid);
    }
    /**
     * New data
     *///http://127.0.0.1:11451/typeTbl/insertOne?tid=5 & amp;name=sda@GetMapping("insertOne") public TypeTbl insert(String name) {
        TypeTbl typeTbl=newTypeTbl();
        typeTbl. setName(name);
        return this.typeTblService.insert(typeTbl);
    }
    /**
     * update data
     *
     *///http://127.0.0.1:11451/typeTbl/updateOne?tid=5 & amp;name=hjk@GetMapping("updateOne") public TypeTbl update(Integer tid, String name) {
        TypeTbl typeTbl=newTypeTbl();
        typeTbl.setTid(tid);
        typeTbl. setName(name);
        return typeTblService. update(typeTbl);
    }
    /**
     * delete data
     *///http://127.0.0.1:11451/typeTbl/deleteOne?tid=5@GetMapping("deleteOne") public booleandeleteById(Integer tid) {
        return typeTblService.deleteById(tid);
    }
}

Source code acquisition: download from the blog homepage “resources”!