栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

最近几周挺忙的,又要准备面试又要参加学校的实习什么的,而且还要准备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 {

    @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 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 findOlderByShopId(int olderShopId);

    @Select("SELECT * FROM ncds.older WHERe olderUserId=#{userId}")
    List 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 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 {
    
    @Select("SELECT * FROM ncds.user WHERe userPhone=#{userPhone} AND password=#{password}")
    boolean loginUser(@Param("userPhone") String userPhone, @Param("password") String password);

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

    

    
    @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);


    
    @Select("SELECT * FROM ncds.good WHERe goodId=#{goodId}")
    Good findHostGood(int goodId);

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

    @Select("SELECT * FROM ncds.shop WHERe shopNickname=#{shopNickname}")
    Shop findShopByName(String shopNickname);
    

    
    @Select("SELECT * FROM ncds.good WHERe goodName LIKE #{goodName}")
    List 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);

    
    @Update("UPDATE ncds.older SET olderState=TRUE WHERe olderId=#{olderId}")
    boolean updateOlderState(@Param("older_id") int olderId);

    
    @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);

    
    @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);

    
    @Select("SELECT * FROM ncds.good")
    List 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 findOlderByShopId(int shopId);

    List findOlderByUserId(int userId);

    Shop findShopById(int shop_id);

    List 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 findOlderByShopId(int shopId) {
        return shopMapper.findOlderByShopId(shopId);
    }

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


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

    @Override
    public List 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 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 {
    
    boolean loginUser(String user_phone, String password);

    
    boolean registerUser(String user_phone, String password);

    
    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);

    
    Good findHostGood(int good_id);

    
    Shop findShopById(int shop_id);

    Shop findShopByName(String shop_nickname);
    

    
    List 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 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 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 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 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 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 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);
    }
    

    
    
}
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 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 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 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 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 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);
    }

    
    @RequestMapping("older_shop_list_select/{shopPhone}")
    public ModelAndView shop_findOlderByUserId(@RequestParam("userId") Integer userId, @PathVariable("shopPhone") String shopPhone) {
        List 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

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

@Component
public class JedisFactory {

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

    
    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;
    }

    
    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;
    }

    
    public List selectHostGoodKey() {
        jedis.auth("hlc");
        Set set = jedis.zrangeByScore("hostGood", 10, 1000);
        List 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 fileOptions(MultipartFile file) {

        List 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("文件版本识别异常");
        }

        
        Sheet sheet = wb.getSheetAt(0);

        
        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);
                
                goodArrayList.add(good);
            }
        }
        return goodArrayList;
    }
}
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);
    }

    
    
    
//    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));
//
//    }

}
时间矫正组件(解决系统时间与数据库时间格式与时区不一致问题)
@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文件
 
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.2
        
        
        
            mysql
            mysql-connector-java
            runtime
        
        
        
            com.alibaba
            druid-spring-boot-starter
            1.2.8
        
        
        
            org.projectlombok
            lombok
            true
        
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
        
        
            commons-codec
            commons-codec
        
        
            org.apache.commons
            commons-lang3
            3.12.0
        
        
        
            org.springframework.boot
            spring-boot-starter-data-redis
        
        
            org.apache.commons
            commons-pool2
            2.11.1
        
        
            redis.clients
            jedis
        
        
        
            org.apache.poi
            poi
            3.15
        
        
            org.apache.poi
            poi-ooxml
            3.15
        
        
            commons-fileupload
            commons-fileupload
            1.3.1
        
        
            commons-io
            commons-io
            2.4
        
    

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/991717.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号