基于springboot+mybatis+thymeleaf+redis+html实现的农村在线交易平台项目(含支付模块)

54 篇文章 2 订阅
14 篇文章 1 订阅

最近几周挺忙的,又要准备面试又要参加学校的实习什么的,而且还要准备web课的结课项目,说是老师帮助我们优秀的项目组申请软件著作权,所以这个在线支付的项目我还是比较重视的,在功能的实现上面下了比较多的功夫,因为不会真的上线有的功能能模拟就模拟了。算是比较满意的了,平时成绩100,结课项目评委分数92(说是前端页面不够美观,不然能给95加吧),综合成绩96,还行,不辜负我整个大三下的自学,大四即将到来,实习单位也找到了,七月份正式上班,最近几天能划水就划划水吧。

本次采取的开发框架还是比较容易上手的微服务springboot开发框架,因为涉及到支付,采用另一个微服务负责支付端的响应。

数据库设计(对应实体类)

商品实体类

@Data
public class Good{
    private int goodId;
    private String goodName;
    private int goodInPrice;
    private int goodOutPrice;
    private int goodReserve;
    private String goodProduct;
    private String goodExTime;
    private int goodShopId;
}

订单实体类

@Data
public class Older implements Serializable {
    private int olderId;
    private int olderUserId;
    private int olderGoodId;
    private int olderShopId;
    private int olderGoodNumber;
    private String olderAddress;
    private String olderGoHomeTime;
    private boolean olderState;
    private String olderDate;
}

商家实体类

@Data
public class Shop {
    private int shopId;
    private String shopNickname;
    private String shopAddress;
    private String shopOwner;
    private String shopPhone;
    private String shopInfo;
    private String password;
}

用户实体类

@Data
public class User {
    private int userId;
    private String userNickname;
    private char userSex;
    private String userHead;
    private String userBrith;
    private String userAddress;
    private String userRegister;
    private String userPhone;
    private String password;
}

dao层(分为两个角色,分别是商家与用户,所以对应的操作也应该不同,当然管理员的角色我也有配置,这个就看大家自己加了,毕竟不是重点)

shopMapper

@Mapper
public interface ShopMapper extends BaseMapper<Good> {

    @Select("SELECT * FROM ncds.shop WHERE shopPhone=#{shopPhone} AND password=#{password}")
    boolean loginShop(@Param("shopPhone") String shop_phone, @Param("password") String password);


    @Insert("INSERT INTO ncds.shop (shopPhone,password) VALUE (#{shopPhone},#{password})")
    boolean registerShop(@Param("shopPhone") String shopPhone, @Param("password") String password);


    @Update("UPDATE ncds.shop SET shopNickname=#{shopNickname},shopAddress=#{shopAddress},shopOwner=#{shopOwner},shopInfo=#{shopInfo} WHERE shopId=#{shopId}")
    boolean refineShop(@Param("shopNickname") String shopNickname, @Param("shopAddress") String shopAddress, @Param("shopOwner") String shopOwner, @Param("shopInfo") String shopInfo, @Param("shopId") int shopId);


    @Update("UPDATE ncds.shop SET password=#{password} WHERE shopId=#{shopId}")
    boolean updateShopPassword(@Param("shopId") int shopId, @Param("password") String password);


    @Select("SELECT * FROM ncds.good WHERE goodId=#{goodId}")
    List<Good> findHostGood(@Param("goodId") int goodId);


    @Insert("INSERT INTO ncds.good (goodName,goodInPrice,goodOutPrice,goodReserve,goodExTime,goodProduct,goodShopId) " +
            "VALUE (#{goodName},#{goodInPrice},#{goodOutPrice},#{goodReserve},#{goodExTime},#{goodProduct},#{goodShopId})")
    boolean saveGood(@Param("goodName") String goodName, @Param("goodInPrice") int goodInPrice, @Param("goodOutPrice") int goodOutPrice,
                     @Param("goodReserve") int goodReserve, @Param("goodExTime") String goodExTime, @Param("goodProduct") String goodProduct, @Param("goodShopId") int goodShopId);

    @Delete("DELETE FROM ncds.good WHERE goodId=#{goodId}")
    boolean deleteGood(@Param("goodId") int goodId);

    @Update("UPDATE ncds.good SET goodReserve=#{goodNumber} WHERE goodId=#{goodId} AND goodName=#{goodName}")
    boolean addGood_number(@Param("goodId") int goodId, @Param("goodNumber") int goodNumber, @Param("goodName") String goodName);

    @Update("UPDATE ncds.good SET goodOutPrice=#{price} WHERE goodId=#{goodId}")
    boolean inSuPriceByGood_id(@Param("goodId") int goodId, @Param("price") int price);


    @Select("SELECT * FROM ncds.older WHERE olderShopId=#{olderShopId}")
    List<Older> findOlderByShopId(int olderShopId);

    @Select("SELECT * FROM ncds.older WHERE olderUserId=#{userId}")
    List<Older> findOlderByUserId(int userId);


    @Select("SELECT * FROM ncds.shop WHERE shopId=#{shopId}")
    Shop findShopById(@Param("shopId") int shopId);


    @Select("SELECT * FROM ncds.good WHERE goodShopId=#{goodShopId}")
    List<Good> findGoodByShopId(int goodShopId);


    @Select("SELECT shopId FROM ncds.shop WHERE shopPhone=#{shopPhone}")
    int findShopIdByShopPhone(String shopPhone);


    @Select("SELECT goodShopId FROM ncds.good WHERE goodId=#{goodId}")
    int findShopIdByGoodId(@Param("goodId") int goodId);

    @Select("SELECT shopPhone FROM ncds.shop WHERE shopId=#{shopId}")
    String findShopPhoneByShopId(@Param("shopId") int shopId);

}

userMapper

@Mapper
public interface UserMapper {
    /*1.登录*/
    @Select("SELECT * FROM ncds.user WHERE userPhone=#{userPhone} AND password=#{password}")
    boolean loginUser(@Param("userPhone") String userPhone, @Param("password") String password);

    /*2.注册*/
    @Insert("INSERT INTO ncds.user(userPhone,password) VALUE (#{userPhone},#{password})")
    boolean registerUser(@Param("userPhone") String userPhone, @Param("password") String password);

    /*补全信息(最开始注册仅仅按照电话与id以及密码 注册)*/

    /**
     * @param userId
     * @param userNickname
     * @param userSex
     * @param userHead     采取的是longblob的mysql数据库格式,利用load_file(文件磁盘路径)的方式
     *                     只需要传入一个路径参数即可实现图片或者视频的存储。我们规定文件路径为D:/ncds/img/...
     * @param userBrith
     * @param userAddress
     * @param userRegister
     * @return boolean
     */
    @Update("UPDATE ncds.user SET userNickname=#{userNickname},userSex=#{userSex},userHead=load_file(#{userHead}),userBrith=#{userBrith},userAddress=#{userAddress},userRegister=#{userRegister},password=#{password} WHERE userId=#{userId}")
    boolean refineUser(@Param("userId") int userId, @Param("userNickname") String userNickname, @Param("userSex") char userSex,
                       @Param("userHead") String userHead, @Param("userBrith") String userBrith, @Param("userAddress") String userAddress, @Param("userRegister") String userRegister, @Param("password") String password);


    /*4.查看热门商品(需要redis数据库查询返回的id排序)*/
    @Select("SELECT * FROM ncds.good WHERE goodId=#{goodId}")
    Good findHostGood(int goodId);

    /*5.搜素商家(分为两种,按照id查与按照name查)*/
    @Select("SELECT * FROM ncds.shop WHERE shopId=#{shopId}")
    Shop findShopById(int shopId);

    @Select("SELECT * FROM ncds.shop WHERE shopNickname=#{shopNickname}")
    Shop findShopByName(String shopNickname);
    /*6.模糊查询,搜索商品(可能不为一个商品)*/

    /**
     * @param goodName 注意测试时需要将传入的参数拼接为“%${goodName}%”的形式
     * @return List<Good>
     */
    @Select("SELECT * FROM ncds.good WHERE goodName LIKE #{goodName}")
    List<Good> findGoodByName(String goodName);

    @Insert("INSERT INTO ncds.older (olderUserId,olderGoodId,olderGoodNumber,olderAddress,olderGoHomeTime,olderState,olderDate,olderShopId)" +
            "VALUE (#{olderUserId},#{olderGoodId},#{olderGoodNumber},#{olderAddress},#{olderGoHomeTime},#{olderState},#{olderDate},#{olderShopId})")
    boolean saveOlder(@Param("olderUserId") int olderUserId, @Param("olderGoodId") int olderGoodId, @Param("olderGoodNumber") int olderGoodNumber, @Param("olderAddress") String olderAddress, @Param("olderGoHomeTime") String olderGoHomeTime, @Param("olderState") boolean olderState, @Param("olderDate") String olderDate, @Param("olderShopId") int olderShopId);

    /*8.支付*/
    @Update("UPDATE ncds.older SET olderState=TRUE WHERE olderId=#{olderId}")
    boolean updateOlderState(@Param("older_id") int olderId);

    /*9.退货处理(就是删除订单,商家的货物退还,计算退款资金)*/
    @Select("SELECT olderUserId FROM ncds.older WHERE olderId=#{olderId}")
    int findUserIdByOlderId(@Param("olderId") Integer olderId);

    @Delete("DELETE FROM ncds.older WHERE olderId=#{olderId}")
    boolean deleteOlder(int olderId);

    @Update("UPDATE ncds.good SET goodReserve=goodReserve+#{olderGoodNumber} WHERE goodShopId=#{shopId}")
    boolean addGood(int shopId, int olderGoodNumber);

    /*11.查询个人信息*/
    @Select("SELECT userPhone FROM ncds.user WHERE userId=#{userId}")
    String findUserPhoneByUserId(@Param("userId") Integer userId);

    @Select("SELECT * FROM ncds.user WHERE userId=#{userId}")
    User findUserById(@Param("userId") int userId);

    @Select("SELECT userId FROM ncds.user WHERE userPhone=#{userPhone}")
    int findUserIdByUserPhone(@Param("userPhone") String userPhone);

    /*13.查询全部商品*/
    @Select("SELECT * FROM ncds.good")
    List<Good> findAllGood();
}

serveice层(基本就是老样子)

shopService与其实现类(service层是redis中间件操作注入层,我姑且是这么叫的)

public interface ShopService {

    boolean loginShop(String shop_phone, String password);

    boolean registerShop(String shop_phone, String password);

    boolean refineShop(String shop_nickname, String shop_address, String shop_owner, String shop_info, int shopId);

    boolean updateShopPassword(int shop_id, String password);

    boolean saveGood(String goodName, int goodInPrice, int goodOutPrice, int goodReserve, String goodExTime, String goodProduct, int goodShopId);

    boolean deleteGood(int good_id);

    boolean addGood_number(int good_id, int good_number, String goodName);

    boolean inSuPriceByGood_id(int good_id, int price);

    List<Older> findOlderByShopId(int shopId);

    List<Older> findOlderByUserId(int userId);

    Shop findShopById(int shop_id);

    List<Good> findGoodByShopId(int goodShopId);

    int findShopIdByShopPhone(String shopPhone);

    boolean saveGoodByFile(MultipartFile file);

    int findShopIdByGoodId(int goodId);

    String findShopPhoneByShopId(int shopId);
}

@Service("ShopService")
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;

    @Autowired
    private FileOption fileOption;

    @Override
    public boolean loginShop(String shop_phone, String password) {
        return shopMapper.loginShop(shop_phone, password);
    }

    @Override
    public boolean registerShop(String shop_phone, String password) {
        return shopMapper.registerShop(shop_phone, password);
    }

    @Override
    public boolean refineShop(String shop_nickname, String shop_address, String shop_owner, String shop_info, int shopId) {
        return shopMapper.refineShop(shop_nickname, shop_address, shop_owner, shop_info, shopId);
    }

    @Override
    public boolean updateShopPassword(int shop_id, String password) {
        return shopMapper.updateShopPassword(shop_id, password);
    }


    @Override
    public boolean saveGood(String goodName, int goodInPrice, int goodOutPrice, int goodReserve, String goodExTime, String goodProduct, int goodShopId) {
        return shopMapper.saveGood(goodName, goodInPrice, goodOutPrice, goodReserve, goodExTime, goodProduct, goodShopId);
    }


    @Override
    public boolean deleteGood(int good_id) {
        return shopMapper.deleteGood(good_id);
    }

    @Override
    public boolean addGood_number(int good_id, int good_number, String goodName) {
        return shopMapper.addGood_number(good_id, good_number, goodName);
    }

    @Override
    public boolean inSuPriceByGood_id(int good_id, int price) {
        return shopMapper.inSuPriceByGood_id(good_id, price);
    }


    @Override
    public List<Older> findOlderByShopId(int shopId) {
        return shopMapper.findOlderByShopId(shopId);
    }

    @Override
    public List<Older> findOlderByUserId(int userId) {
        return shopMapper.findOlderByUserId(userId);
    }


    @Override
    public Shop findShopById(int shop_id) {
        return shopMapper.findShopById(shop_id);
    }

    @Override
    public List<Good> findGoodByShopId(int goodShopId) {
        return shopMapper.findGoodByShopId(goodShopId);
    }

    @Override
    public int findShopIdByShopPhone(String shopPhone) {
        return shopMapper.findShopIdByShopPhone(shopPhone);
    }

    @Override
    public boolean saveGoodByFile(MultipartFile file) {
        boolean flag = true;
        List<Good> goodList = fileOption.fileOptions(file);
        for (Good good : goodList) {
            flag = saveGood(good.getGoodName(), good.getGoodInPrice(), good.getGoodOutPrice(),
                    good.getGoodReserve(), good.getGoodExTime(), good.getGoodProduct()
                    , good.getGoodShopId());
        }
        return flag;
    }

    @Override
    public int findShopIdByGoodId(int goodId) {
        return shopMapper.findShopIdByGoodId(goodId);
    }

    @Override
    public String findShopPhoneByShopId(int shopId) {
        return shopMapper.findShopPhoneByShopId(shopId);
    }
}

userService与其实现类

public interface UserService {
    /*1.登录*/
    boolean loginUser(String user_phone, String password);

    /*2.注册*/
    boolean registerUser(String user_phone, String password);

    /*补全信息(最开始注册仅仅按照电话与id以及密码 注册)*/
    boolean refineUser(int user_id, String user_nickname, char user_sex,
                       String user_head, String user_brith, String user_address, String user_register,String password);

    /*4.查看热门商品(需要redis数据库查询返回的id排序)*/
    Good findHostGood(int good_id);

    /*5.搜素商家(分为两种,按照id查与按照name查)*/
    Shop findShopById(int shop_id);

    Shop findShopByName(String shop_nickname);
    /*6.模糊查询,搜索商品(可能不为一个商品)*/

    /**
     * @param good_name 注意测试时需要将传入的参数拼接为“%${good_name}%”的形式
     * @return List<Good>
     */
    List<Good> findGoodByName(String good_name);

    boolean updateOlderState(int older_id);

    String findUserPhoneByUserId(Integer userId);

    boolean deleteOlder(int older_id);

    boolean addGood(int shop_id, int older_good_number);

    User findUserById(int user_id);
    int findUserIdByOlderId(Integer olderId);

    int findUserIdByUserPhone(String userPhone);
    List<Good> findAllGood();

    boolean saveOlder(int olderUserId,int olderGoodId,int olderGoodNumber,String olderAddress,String olderGoHomeTime,boolean olderState,String olderDate, int olderShopId);
}
@Service("UserService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean loginUser(String user_phone, String password) {
        return userMapper.loginUser(user_phone,password);
    }

    @Override
    public boolean registerUser(String user_phone, String password) {
        return userMapper.registerUser(user_phone,password);
    }

    @Override
    public boolean refineUser(int user_id, String user_nickname, char user_sex, String user_head, String user_brith, String user_address, String user_register,String password) {
        return userMapper.refineUser(user_id,user_nickname,user_sex,user_head,user_brith,user_address,user_register,password);
    }

    @Override
    public Good findHostGood(int good_id) {
        return userMapper.findHostGood(good_id);
    }

    @Override
    public Shop findShopById(int shop_id) {
        return userMapper.findShopById(shop_id);
    }

    @Override
    public Shop findShopByName(String shop_nickname) {
        return userMapper.findShopByName(shop_nickname);
    }

    @Override
    public List<Good> findGoodByName(String good_name) {
        return userMapper.findGoodByName(good_name);
    }


    @Override
    public boolean updateOlderState(int older_id) {
        return userMapper.updateOlderState(older_id);
    }

    @Override
    public String findUserPhoneByUserId(Integer userId) {
        return userMapper.findUserPhoneByUserId(userId);
    }

    @Override
    public boolean deleteOlder(int older_id) {
        return userMapper.deleteOlder(older_id);
    }

    @Override
    public boolean addGood(int shop_id, int older_good_number) {
        return userMapper.addGood(shop_id,older_good_number);
    }

    @Override
    public User findUserById(int user_id) {
        return userMapper.findUserById(user_id);
    }

    @Override
    public int findUserIdByOlderId(Integer olderId) {
        return userMapper.findUserIdByOlderId(olderId);
    }

    @Override
    public int findUserIdByUserPhone(String userPhone) {
        return userMapper.findUserIdByUserPhone(userPhone);
    }


    @Override
    public List<Good> findAllGood() {
        return userMapper.findAllGood();
    }

    @Override
    public boolean saveOlder(int olderUserId, int olderGoodId, int olderGoodNumber, String olderAddress, String olderGoHomeTime, boolean olderState, String olderDate, int olderShopId) {
        return userMapper.saveOlder(olderUserId,olderGoodId,olderGoodNumber,olderAddress,olderGoHomeTime,olderState,olderDate,olderShopId);
    }
}

controller层(各种Url能记住吗?)

userController

@RequestMapping("User")
@RestController
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private ShopService shopService;
    @Autowired
    private JedisFactory jedisFactory;

    /*注册*/
    @RequestMapping("register")
    public ModelAndView registerF() {
        return new ModelAndView("/register/register_user");
    }

    @PostMapping("register_user")
    public ModelAndView registerUser(String userPhone, String password) {
        boolean registerUser = userService.registerUser(userPhone, password);
        if (registerUser) {
            loginF();
        }
        return registerF();
    }

    /*登录*/
    @RequestMapping("login")
    public ModelAndView loginF() {
        return new ModelAndView("/login/login_user");
    }

    @PostMapping("login_user")
    public ModelAndView loginUser(String userPhone, String password) {
        boolean loginKey = jedisFactory.selectLoginKey(userPhone, password);
        if (loginKey) {
            return index_user(userPhone);
        } else {
            boolean loginUser = userService.loginUser(userPhone, password);
            if (loginUser) {
                return index_user(userPhone);
            }
        }
        return loginF();
    }

    /*主页*/
    @RequestMapping("index_user")
    public ModelAndView index_user(String userPhone) {
        List<Good> goodList = userService.findAllGood();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("goodList", goodList);
        modelAndView.addObject("userPhone", userPhone);
        modelAndView.setViewName("/index/user/index");
        return modelAndView;
    }

    @RequestMapping("index_user_return/{userPhone}")
    public ModelAndView index_user_return(@PathVariable("userPhone") String userPhone) {
        List<Good> goodList = userService.findAllGood();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("goodList", goodList);
        modelAndView.addObject("userPhone", userPhone);
        modelAndView.setViewName("/index/user/index");
        return modelAndView;
    }

    /*用户查看个人信息*/
    @RequestMapping("find_user/{userPhone}")
    public ModelAndView find_user(@PathVariable("userPhone") String userPhone) {
        int id = userService.findUserIdByUserPhone(userPhone);
        User user = userService.findUserById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("User", user);
        modelAndView.addObject("userPhone", userPhone);
        modelAndView.setViewName("/index/user/find_user");
        return modelAndView;
    }

    /*用户修改个人信息*/
    @RequestMapping("update_userF/{userPhone}")
    public ModelAndView update_userF(@PathVariable("userPhone") String userPhone) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userPhone", userPhone);
        modelAndView.setViewName("index/user/update_user");
        return modelAndView;
    }

    @RequestMapping("update_user/{userPhone}")
    public ModelAndView update_user(@PathVariable("userPhone") String userPhone, @RequestParam("userNickname") String userNickname, @RequestParam("userSex") char userSex,
                                    @RequestParam("userHead") String userHead, @RequestParam("userBrith") String userBrith,
                                    @RequestParam("userAddress") String userAddress, @RequestParam("userRegister") String userRegister, @RequestParam("password") String password) {
        int id = userService.findUserIdByUserPhone(userPhone);
        boolean flag = userService.refineUser(id, userNickname, userSex, userHead, userBrith, userAddress, userRegister, password);
        if (flag)
            return find_user(userPhone);
        else
            return update_userF(userPhone);
    }

    /*查看订单*/
    @RequestMapping("older_user_list/{userPhone}")
    public ModelAndView older_user_list(@PathVariable("userPhone") String userPhone) {
        int id = userService.findUserIdByUserPhone(userPhone);
        List<Older> olderList = shopService.findOlderByUserId(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userPhone", userPhone);
        modelAndView.addObject("olderList", olderList);
        modelAndView.setViewName("/List/older_user_list");
        return modelAndView;
    }

    /*用户下单弹窗*/
    @RequestMapping("older_user_addF/{userPhone}")
    public ModelAndView older_user_addF(@PathVariable("userPhone") String userPhone) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userPhone", userPhone);
        modelAndView.setViewName("/index/user/older_user_add");
        return modelAndView;
    }

    @RequestMapping("older_user_add/{userPhone}")
    public ModelAndView older_user_add(@PathVariable("userPhone") String userPhone,
                                       @RequestParam("olderGoodId") int olderGoodId, @RequestParam("olderGoodNumber") int olderGoodNumber,
                                       @RequestParam("olderAddress") String olderAddress, @RequestParam("olderGoHomeTime") String olderGoHomeTime, @RequestParam("date") String date) {
        int shopId = shopService.findShopIdByGoodId(olderGoodId);
        int userId = userService.findUserIdByUserPhone(userPhone);
        boolean state = false;
        boolean saveOlder = userService.saveOlder(userId, olderGoodId, olderGoodNumber, olderAddress, olderGoHomeTime, state, date, shopId);
        if (saveOlder)
            return older_user_list(userPhone);
        else
            return older_user_addF(userPhone);
    }

    /*用户取消订单*/
    @RequestMapping("del_older_user/{olderId}")
    public ModelAndView del_older_user(@PathVariable("olderId") Integer olderId) {
        int userId = userService.findUserIdByOlderId(olderId);
        String userPhone = userService.findUserPhoneByUserId(userId);
        boolean deleteOlder = userService.deleteOlder(olderId);
        if (deleteOlder)
            return older_user_list(userPhone);
        else
            return older_user_list(userPhone);
    }
    /*用户确认付款(跳转网址定位http://192.168.10.105:8081/order/form)*/

    /*用户查询商品按照商品名称,模糊查询*/
    /*用户查询订单按照日期查询*/
}

shopController

@RestController
@RequestMapping("Shop")
public class ShopController {

    @Autowired
    private ShopService shopService;
    @Autowired
    private UserService userService;
    @Autowired
    private JedisFactory jedisFactory;

    /*注册*/
    @RequestMapping("register")
    public ModelAndView registerF() {
        return new ModelAndView("register/register_shop");
    }

    @PostMapping("register_shop")
    public ModelAndView registerShop(String shopPhone, String password) {
        boolean registerShop = shopService.registerShop(shopPhone, password);
        if (registerShop)
            return loginF();
        return registerF();
    }

    /*登录*/
    @RequestMapping("login")
    public ModelAndView loginF() {
        return new ModelAndView("login/login_shop");
    }

    @PostMapping("login_shop")
    public ModelAndView loginShop(String shopPhone, String password) {
        boolean loginKey = jedisFactory.selectLoginKey(shopPhone, password);
        if (loginKey) {
            return index_shop(shopPhone);
        } else {
            boolean loginShop = shopService.loginShop(shopPhone, password);
            if (loginShop)
                return index_shop(shopPhone);
        }
        return loginF();

    }

    /*商家主页数据加载与渲染*/
    @RequestMapping("index_shop")
    public ModelAndView index_shop(String shopPhone) {
        int id = shopService.findShopIdByShopPhone(shopPhone);
        List<Good> goodList = shopService.findGoodByShopId(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.addObject("goodList", goodList);
        modelAndView.setViewName("index/shop/index");
        return modelAndView;
    }

    /*跳转返回主页用,时刻拿着一个令牌*/
    @RequestMapping("index_shop_return/{shopPhone}")
    public ModelAndView index_shop_return(@PathVariable("shopPhone") String shopPhone) {
        List<Good> goodList = shopService.findGoodByShopId(shopService.findShopIdByShopPhone(shopPhone));
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.addObject("goodList", goodList);
        modelAndView.setViewName("index/shop/index");
        return modelAndView;
    }

    /*主页面添加商品*/
    @RequestMapping("add_goodF/{shopPhone}")
    public ModelAndView add_goodF(@PathVariable("shopPhone") String shopPhone) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.setViewName("index/shop/add_good");
        return modelAndView;
    }

    /*单个商品添加*/
    @RequestMapping("add_good/{shopPhone}")
    public ModelAndView add_good(@PathVariable("shopPhone") String shopPhone, @RequestParam("goodName") String goodName, @RequestParam("goodInPrice") Integer goodInPrice, @RequestParam("goodOutPrice") Integer goodOutPrice, @RequestParam("goodReserve") Integer goodReserve, @RequestParam("goodExTime") String goodExTime, @RequestParam("goodProduct") String goodProduct, @RequestParam("goodShopId") Integer goodShopId) {
        boolean saveGood = shopService.saveGood(goodName, goodInPrice, goodOutPrice, goodReserve, goodExTime, goodProduct, goodShopId);
        if (saveGood) {
            return index_shop(shopPhone);
        }
        return good_shop_list(shopPhone);
    }

    /*文件导入添加*/
    @RequestMapping("add_good_file/{shopPhone}")
    public ModelAndView add_good_file(@RequestParam("file") MultipartFile file, @PathVariable("shopPhone") String shopPhone) {
        boolean saveGoodByFile = shopService.saveGoodByFile(file);
        if (saveGoodByFile) {
            return index_shop(shopPhone);
        }
        return good_shop_list(shopPhone);
    }

    /*商家货架数据加载与渲染*/
    @RequestMapping("good_shop_list/{shopPhone}")
    public ModelAndView good_shop_list(@PathVariable("shopPhone") String shopPhone) {
        ModelAndView modelAndView = new ModelAndView();
        int id = shopService.findShopIdByShopPhone(shopPhone);
        List<Good> goodList = shopService.findGoodByShopId(id);
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.addObject("goodList", goodList);
        modelAndView.setViewName("List/good_shop_list");
        return modelAndView;
    }

    /*删除商品*/
    @RequestMapping("delete_good/{goodId}")
    public ModelAndView delete_good(@PathVariable("goodId") Integer goodId) {
        int shopId = shopService.findShopIdByGoodId(goodId);
        boolean deleteGood = shopService.deleteGood(goodId);
        String shopPhone = shopService.findShopPhoneByShopId(shopId);
        /*这里需要加上一个删除失败的跳转逻辑*/
        return good_shop_list(shopPhone);
    }

    /*商家订单统计页面的查看*/
    @RequestMapping("older_shop_list/{shopPhone}")
    public ModelAndView older_shop_list(@PathVariable("shopPhone") String shopPhone) {
        ModelAndView modelAndView = new ModelAndView();
        int id = shopService.findShopIdByShopPhone(shopPhone);
        List<Older> olderList = shopService.findOlderByShopId(id);
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.addObject("olderList", olderList);
        modelAndView.setViewName("List/older_shop_list");
        return modelAndView;
    }

    /*商家查询自己的商品按照商品名称查询*/
    @RequestMapping("shop_findGoodByGoodName/{shopPhone}")
    public ModelAndView shop_shop_findGoodByName(@RequestParam("goodName") String goodName, @PathVariable("shopPhone") String shopPhone) {
        /*模糊查询,手动拼接*/
        List<Good> goodList = userService.findGoodByName("%" + goodName + "%");
        if (goodList != null) {
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.addObject("goodList", goodList);
            modelAndView.addObject("shopPhone", shopPhone);
            modelAndView.setViewName("List/good_shop_list");
            return modelAndView;
        }
        return index_shop(shopPhone);
    }

    /*商家搜索订单按照用户ID*/
    @RequestMapping("older_shop_list_select/{shopPhone}")
    public ModelAndView shop_findOlderByUserId(@RequestParam("userId") Integer userId, @PathVariable("shopPhone") String shopPhone) {
        List<Older> olderList = shopService.findOlderByUserId(userId);
        if (olderList != null) {
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.addObject("olderList", olderList);
            modelAndView.addObject("shopPhone", shopPhone);
            modelAndView.setViewName("List/older_shop_list");
            return modelAndView;
        }
        return older_shop_list(shopPhone);
    }

    /*商家调整价格窗口的弹出*/
    @RequestMapping("update_good_priceF/{shopPhone}")
    public ModelAndView update_good_priceF(@PathVariable("shopPhone") String shopPhone) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.setViewName("index/shop/update_good_price");
        return modelAndView;
    }

    @RequestMapping("update_good_price/{shopPhone}")
    public ModelAndView update_good_price(@PathVariable("shopPhone") String shopPhone, @RequestParam("goodId") Integer goodId, @RequestParam("goodName") String goodName, @RequestParam("goodPrice") Integer goodPrice) {
        boolean inSuPriceByGoodId = shopService.inSuPriceByGood_id(goodId, goodPrice);
        if (inSuPriceByGoodId)
            return good_shop_list(shopPhone);
        return update_good_priceF(shopPhone);
    }

    /*商家进货窗口弹出*/
    @RequestMapping("add_good_numberF/{shopPhone}")
    public ModelAndView add_good_numberF(@PathVariable("shopPhone") String shopPhone) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("shopPhone", shopPhone);
        modelAndView.setViewName("index/shop/add_good_number");
        return modelAndView;
    }

    @RequestMapping("add_good_number/{shopPhone}")
    public ModelAndView add_good_number(@PathVariable("shopPhone") String shopPhone, @RequestParam("goodId") Integer goodId, @RequestParam("goodName") String goodName, @RequestParam("goodNumber") Integer goodNumber) {
        boolean addGoodNumber = shopService.addGood_number(goodId, goodNumber, goodName);
        if (addGoodNumber)
            return good_shop_list(shopPhone);
        System.out.println("----------------进货操作失败-------------------");
        return add_good_numberF(shopPhone);
    }

    /*商家查看自家店铺信息*/
    @RequestMapping("find_shop/{shopPhone}")
    public ModelAndView find_shop(@PathVariable("shopPhone") String shopPhone) {
        int id = shopService.findShopIdByShopPhone(shopPhone);
        Shop shop = shopService.findShopById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("Shop", shop);
        modelAndView.setViewName("index/shop/find_shop");
        return modelAndView;
    }

    @RequestMapping("update_shopF/{shopPhone}")
    public ModelAndView update_shopF(@PathVariable("shopPhone") String shopPhone) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index/shop/update_shop");
        modelAndView.addObject("shopPhone", shopPhone);
        return modelAndView;
    }

    @RequestMapping("update_shop/{shopPhone}")
    public ModelAndView update_shopInfo(@PathVariable("shopPhone") String shopPhone, @RequestParam("shopNickname") String shopNickname
            , @RequestParam("shopAddress") String shopAddress, @RequestParam("shopOwner") String shopOwner
            , @RequestParam("password") String password, @RequestParam("shopInfo") String shopInfo) {
        int id = shopService.findShopIdByShopPhone(shopPhone);
        boolean refineShop = shopService.refineShop(shopNickname, shopAddress, shopOwner, shopInfo, id);
        boolean updateShopPassword = shopService.updateShopPassword(id, password);
        if (refineShop && updateShopPassword) {
            return index_shop(shopPhone);
        }
        return update_shopF(shopPhone);
    }

    /*注销商家*/

}

辅助组件

redis组件

1、jedisUtils

/*redis生成连接池JedisPool的配置工具*/
public class JedisUntil {

    private static JedisPool jedisPool = null;

    public static JedisPool getJedisPoolFactory() {

        if (jedisPool == null) {
            synchronized (JedisUntil.class) {
                if (jedisPool == null) {
                    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
                    jedisPoolConfig.setMaxIdle(32);
                    jedisPoolConfig.setMaxTotal(200);
                    jedisPoolConfig.setTestOnBorrow(false);
                    jedisPoolConfig.setBlockWhenExhausted(true);

                    jedisPool = new JedisPool(jedisPoolConfig, "192.168.20.150", 6379);
                }
            }
        }
        return jedisPool;
    }

    public void release(Jedis jedis, JedisPool jedisPool) {
        if (jedisPool != null) {
            jedis.close();
        }
    }
}

2、jedisFactory

/*创建jedis生成工厂为我们创建jedis对象并操作redis数据库*/
@Component
public class JedisFactory {

    static JedisPool jedisPool = JedisUntil.getJedisPoolFactory();
    static Jedis jedis = jedisPool.getResource();

    /*登录走redis,第一次登录即将它加入redis数据库(用 phone-password 键值对存储)*/
    public void addLoginKey(String shopPhone, String password) {
        jedis.auth("hlc");
        jedis.setex(shopPhone, 120, password);
        jedis.close();
    }

    public boolean selectLoginKey(String shopPhone, String password) {
        jedis.auth("hlc");
        String V = jedis.get(shopPhone);
        if (V != null) {
            System.out.println("走缓存登录");
            jedis.close();
            return true;
        } else {
            addLoginKey(shopPhone, password);
            selectLoginKey(shopPhone, password);
        }
        jedis.close();
        return false;
    }

    public boolean addGoodHostKey(int goodId) {
        Long i = null;
        jedis.auth("hlc");
        i = jedis.zadd("hostGood", Double.parseDouble("1"), String.valueOf(goodId));
        jedis.close();
        return i != null;
    }

    /*访问一次就给该商品的热度增加1*/
    public boolean incrGoodHostKeyValue(int goodId) {
        jedis.auth("hlc");
        Long i = null;
        i = jedis.zrank("hostGood", String.valueOf(goodId));
        if (i != null) {
            jedis.zincrby("hostGood", 1, String.valueOf(goodId));
            jedis.close();
            return true;
        }
        return addGoodHostKey(goodId);
    }

    /*当商品下架时要删除热度*/
    public boolean delGoodHostKey(int goodId) {
        jedis.auth("hlc");
        Long i = null;
        i = jedis.zrem("host", String.valueOf(goodId));
        jedis.close();
        return i != null;
    }

    /*c查询热度在10以上的商品排行*/
    public List<Integer> selectHostGoodKey() {
        jedis.auth("hlc");
        Set<String> set = jedis.zrangeByScore("hostGood", 10, 1000);
        List<Integer> hostList = new ArrayList<>();
        for (String i : set) {
            hostList.add(Integer.valueOf(i));
        }
        jedis.close();
        System.out.println("走缓存查看热度商品");
        return hostList;
    }
}

 文件导入自定义的Excel解析组件

/*文件导入解析数据实现货物的批量导入*/
@Component
public class FileOption {

    public List<Good> fileOptions(MultipartFile file) {

        List<Good> goodArrayList = new ArrayList<>();

        /*获取文件名*/
        String fileName = file.getOriginalFilename();
        /*获取文件后缀*/
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
        /*创建文件输入流对象*/
        InputStream ins = null;
        try {
            ins = file.getInputStream();
        } catch (IOException e) {
            System.out.println("文件导入异常");
            e.printStackTrace();
        }
        /*获取工作薄对象*/
        Workbook wb = null;
        try {
            /*根据文件类型将文件输入流对象给到工作薄对象的内容里去*/
            if (suffix.equals("xlsx")) {
                wb = new XSSFWorkbook(ins);
            } else {
                wb = new HSSFWorkbook(ins);
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件版本识别异常");
        }

        /*获取excel表单*/
        Sheet sheet = wb.getSheetAt(0);

        /* line = 2 :从表的第三行开始获取记录*/
        if (null != sheet) {
            for (int line = 2; line <= sheet.getLastRowNum(); line++) {
                /*创建对象,封装数据*/
                Good good = new Good();
                /*创建行对象,便于逐行操作单元格*/
                Row row = sheet.getRow(line);
                if (null == row) {
                    continue;
                }
                /* 判断单元格类型是否为文本类型 */
                if (1 != row.getCell(0).getCellType()) {
                    System.out.println("单元格类型不是文本类型");
                }
                /*获取第一个单元格的内容并设置对象的属性*/
                row.getCell(0).setCellType(Cell.CELL_TYPE_NUMERIC);
                Integer good_id = (int) row.getCell(0).getNumericCellValue();
                good.setGoodId(good_id);
                /* 获取第二个单元格的内容并设置对象的属性*/
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                String good_name = row.getCell(1).getStringCellValue();
                good.setGoodName(good_name);
                /*获取第三个单元格内容并设置对象的属性*/
                row.getCell(2).setCellType(Cell.CELL_TYPE_NUMERIC);
                Integer good_inPrice = (int) row.getCell(2).getNumericCellValue();
                good.setGoodInPrice(good_inPrice);
                /*获取第四行数据并设置对象属性*/
                row.getCell(3).setCellType(Cell.CELL_TYPE_NUMERIC);
                Integer good_outPrice = (int) row.getCell(3).getNumericCellValue();
                good.setGoodOutPrice(good_outPrice);
                /*获取第五单元格并设置对象属性*/
                row.getCell(4).setCellType(Cell.CELL_TYPE_NUMERIC);
                Integer good_reserve = (int) row.getCell(4).getNumericCellValue();
                good.setGoodReserve(good_reserve);
                /*获取第六单元格并设置对象属性*/
                String good_product = String.valueOf(row.getCell(5).getDateCellValue());
                good.setGoodProduct(good_product);
                /*获取第七单元格并设置对象属性*/
                String good_exTime = String.valueOf(row.getCell(6).getDateCellValue());
                good.setGoodExTime(good_exTime);
                /*获取第八单元格并设置对象属性*/
                Integer good_shop_id = (int) row.getCell(7).getNumericCellValue();
                good.setGoodShopId(good_shop_id);
                /*将这个对象插入List容器里*/
                goodArrayList.add(good);
            }
        }
        return goodArrayList;
    }
}

MD5加密组件

/*加密算法:MD5加密的使用,主要是二次加密加盐的技术*/
@Component
public class MD5 {

    public static String slat = "1a2b3c4d";

    public String md5_hlc(String src) {
        return DigestUtils.md5Hex(src);
    }

    /*前端加密的步骤与这一样,注意盐的位置与盐的值*/
    public String inputPassToFromPass(String inputPass) {
        String slat = "java_secKill";
        String str = slat.charAt(0) +
                slat.charAt(1) + inputPass +
                slat.charAt(2);
        return md5_hlc(str);
    }

    public String PassToDbPass(String FromPass, String slat) {
        String str = slat.charAt(2) +
                slat.charAt(1) + FromPass +
                slat.charAt(0);
        return md5_hlc(str);

    }

    public String inputPassToDbPass(String inputPass) {
        String fromPass = inputPassToFromPass(inputPass);
        return PassToDbPass(fromPass, slat);
    }

    /*测试加密技术*/
    /*444bcbf09f10ee179b8c8d52bf834033(数据库昵称:小年 的实体密码 / 前端加密出现的加密后密码)*/
    /*经过加密之后的密码因该不是这个,原始的密码经过MD5加密之后就发生了加密变化*/
//    public static void main(String[] args) {
//        MD5 m1 = new MD5();
//        System.out.println(m1.inputPassToFromPass("hlc123"));
//        System.out.println(m1.PassToDbPass(m1.inputPassToFromPass("hlc123"), slat));
//
//    }

}

时间矫正组件(解决系统时间与数据库时间格式与时区不一致问题)

/*
 * 日期矫正组件:java提取系统时间可能会减少8小时,由于时区问题,所以需要将时区调整到东八区,
 * 另外数据库日期格式可能与java封装工具包可能存在差异,所以需要转换格式。
 * */
@Component
public class TimeC {

    public String getSystemTime() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        Date date = sdf.parse(sdf.format(new Date()));
        return date.toString();
    }

}

 前端页面

需要的评论区留言我会回复的。

application.yml文件

spring:
  application:
    #应用名
    name: SecKill
  datasource:
    name: defaultDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ncds?serverTimezone=UTC
    username: root
    password: 123456
    #数据库连接池
    druid:
      name: NCDS
      min-idle: 32
      max-active: 100
      default-auto-commit: true
      max-wait: 3000
  mvc:
    static-path-pattern: /static/**

  thymeleaf:
    #是否利用缓存
    cache: false
    mode: HTML5
  redis:
    host: 192.168.20.150
    port: 6379
    password: hlc
    database: 1
    jedis:
      pool:
        max-idle: 32
        max-wait: 3000
        min-idle: 8
        max-active: 20

server:
  port: 8080

pom文件

 <dependencies>
        <!--跳转模板引擎-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!--springMVC-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--mybatis plus 依赖与代码生成器依赖-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>
        <!--mysql数据库驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--数据库连接池-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.8</version>
        </dependency>
        <!--lombok开发插件-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!--测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--md5依赖-->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>
        <!--redis数据库-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.11.1</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
        <!--文件导入依赖-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.15</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.15</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>

支付端口呢?当然是在我上一篇文章里了!那个就是解决支付实现的模块代码。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Spring Boot是一个基于Spring框架的快速开发框架,通过提供一系列的开箱即用的功能和优化配置,简化了Java后台应用的开发流程。 Thymeleaf是一个Java模板引擎,用于在服务端渲染HTML页面。它可以和Spring Boot结合使用,通过在HTML页面中使用Thymeleaf的语法,实现页面的动态渲染和数据绑定。 Layui是一个国内比较流行的前端UI框架,提供了大量的CSS样式和JavaScript组件,可以快速构建美观、响应式的前端界面。 Apache Shiro是一个强大的开源安全框架,可以用于认证、授权和加密操作。它提供了对用户身份验证、角色和权限管理的支持,可以帮助开发者快速实现应用的安全控制。 Redis是一个高性能的内存数据库,常用于缓存和存储数据。它支持多种数据结构和操作,可以用于实现分布式锁、消息队列等功能,提高系统的性能和可扩展性。 MyBatis Plus是一个基于MyBatis框架的增强工具,提供了更简单、更便捷的数据库操作方式。它通过代码生成器和一系列的增强功能,简化了数据层的开发工作,提高了开发效率。 综上所述,可以使用Spring Boot作为后台框架,集成Thymeleaf实现页面渲染和数据绑定,使用Layui构建前端界面,使用Apache Shiro进行安全控制,使用Redis进行数据缓存和存储,使用MyBatis Plus进行数据库操作。这样搭建的后台系统可以实现高效、安全、可扩展的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ForestSpringH

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值