基于springboot的助农服务平台

基于springboot的助农服务app

介绍

2024届软件工程毕业设计

	该项目是基于springboot的助农App的设计及实现,主要实现了管理员,用户,商家三个端的设计,其中主要实现的功能有产品模块,订单模块,购物车模块,以及相关联的管理模块,秒杀等,帮助农民出售农作物,提高农业水平的发展,提高农民的收入,方便农民出售自产的农产品。系统使用MVC设计模式,用户端以及商家端采用uniapp+springboot+mybatis+mybatis-plus实现,后台管理系统采用vue+springboot+mybatis+mybatis-plus实现。数据存储使用mysql数据库,同时使用elasticSearch全文搜索,加快和前端交互的效率。

​ 管理员端页面效果图如下,其中权限管理中使用了springsecurity框架,作为动态权限。各个表单的添加和修改功能均测试过,无任何问题。

​ 其中,springsecurity的核心代码如下,配置了过滤器,拦截规则,异常处理器等

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.cors().and().csrf().disable()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            //退出登录
            .and()
            .logout()
            .logoutSuccessHandler(jwtLogoutSuccessHandler)
            // 配置拦截规则
            .and()
            .authorizeRequests()
            .antMatchers(URL_WHITELIST).permitAll()
            .anyRequest().access(
                    "@customPermissionEvaluator.hasPermission(authentication, request)")
            // 异常处理器
            .and()
            .exceptionHandling()
            .authenticationEntryPoint(jwtAuthenticationEntryPoint)
            .accessDeniedHandler(jwtAccessDeniedHandler)
            // 配置自定义的过滤器
            .and()
            .addFilter(jwtAuthenticationFilter())
            ;
    ;
}

项目中还使用了xxl-job作为定时任务,xxl-job核心配置类如下所示

@Slf4j
@Configuration
public class XxlJobConfig {

//    private Logger logger = LoggerFactory.getLogger(XxlJobConfiguration.class);

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${xxl.job.accessToken}")
    private String accessToken;

    @Value("${xxl.job.executor.appname}")
    private String appname;
    
    @Value("${xxl.job.executor.port}")
    private int port;
    
    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        // registry jobhandler
//        XxlJobSpringExecutor.registJobHandler("beanClassJobHandler", new BeanMethodJobHandler());
        // init executor
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appname);
//        xxlJobSpringExecutor.setAddress(address);
//        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
//        xxlJobSpringExecutor.setLogPath(logPath);
//        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobSpringExecutor;
    }
}

jwt令牌权限过滤器代码如下所示

protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    String jwt = request.getHeader(jwtUtils.getHeader());
    if (isPathWithoutAuthentication(request.getRequestURI())) {
        chain.doFilter(request, response);
        return;
    }
    Claims claim = jwtUtils.getClaimsByToken(jwt);
    if (claim == null) {
        request.setAttribute("jwtExceptionMessage","token 异常");
        throw new JwtException("token 异常");
    }
    if (jwtUtils.isTokenExpired(claim)) {
        request.setAttribute("jwtExceptionMessage","token 已过期");
        throw new JwtException("token 已过期");
    }
    String username = claim.getSubject();
    Object tokenIn = redisUtil.get(RedisKeyUtil.getRedisKeyOfGetToken(username));
    if (tokenIn!=null&&!tokenIn.toString().equals(jwt)){
        request.setAttribute("jwtExceptionMessage","用户已在其他地方登录");
        throw new JwtException("用户已在其他地方登录");
    }
    UserPo userPo = userService.findByUsername(username);
    // 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录
    log.info("登录的用户是:"+username);
    UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(username,
                    null, userDetailService.getUserAuthority(userPo.getId()));
    token.setDetails(userPo.getId());
    SecurityContextHolder.getContext().setAuthentication(token);
    chain.doFilter(request, response);
}

image-20240719172639860

image-20240719172724534

image-20240719172750505
在这里插入图片描述

image-20240719172834076

image-20240719172902706

image-20240719172944577

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240719173042078

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240719173243927

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240721214832268

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

用户端页面如下图所示,采用的是app的形式展示,使用Hbuilder作为开发工具开发,个人觉得uniapp的语法和vue的语法极其相似=_=

用户端有秒杀的功能,使用了redis缓存秒杀数据,同时使用了rabbitmq作为消息队列。在首页的推荐中,使用的是基于物品的协同过滤算法。

登录页面包括用户名密码登录和邮箱验证码登录,邮箱验证码使用到的是springmail技术。

redis核心配置类代码如下所示

@Configuration
public class RedisConfig {
    @Bean(name = "redisTemplate")
    public RedisTemplate<String, Object> getRedisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
        redisTemplate.setConnectionFactory(factory);

        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();

        redisTemplate.setKeySerializer(stringRedisSerializer); // key的序列化类型

        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        // 方法过期,改为下面代码
//        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance ,
                ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
        jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
        jackson2JsonRedisSerializer.setObjectMapper(objectMapper);

        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); // value的序列化类型
        redisTemplate.setHashKeySerializer(stringRedisSerializer);
        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }
}

秒杀中使用了redisson锁,防止超卖现象,redisson配置类代码如下所示。

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.database}")
    private int database;

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private String port;

    @Value("${spring.redis.password}")
    private String password;

    @Bean(value = "redissonClient", destroyMethod = "shutdown")
    public RedissonClient redissonClient() throws Exception {

        Config config = new Config();
        config.useSingleServer().setAddress(String.format("redis://%s:%s", this.host, this.port));
        if (!this.password.isEmpty()) {
            config.useSingleServer().setPassword(this.password);
        }
        config.useSingleServer().setDatabase(this.database);

        StringCodec codec = new StringCodec();
        config.setCodec(codec);
        return Redisson.create(config);
    }

}

image-20240721215856378

image-20240721220019814

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240721220344228

image-20240721220617122

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240721220835056

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240721220934903

image-20240721221015799

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240721221047033

image-20240721221059239

image-20240721221113589

image-20240721221140338

image-20240721221150936

image-20240721221202793

image-20240721221410852

image-20240721221432414

以上是用户端买家的各个功能的部分截图,时间原因不一一阐述。

最后是商家端App,商家端App主要功能有数据台查看,店铺管理,商品管理,订单管理,以及参加秒杀活动的管理。商家端效果图如下所示。

image-20240721230018188

image-20240721230036704

image-20240721230100668

image-20240721230114601

image-20240721230136099

image-20240721230152791

image-20240721230210599

image-20240721230222368

image-20240721230237368

image-20240721230301008

image-20240721230318840

image-20240721230332262

image-20240721230418729

image-20240721230626159

image-20240721230638603

​ 以上是基于Springboot的助农服务项目的介绍,运用到的技术和技术栈主要有springboot、mybaits、mybatisplus、redis、rabbitmq、elasticsearch、springsecurity、jwt令牌、springmail等等,同时自定义了一个基于物品的协同过滤算法,给用户做推荐。数据库使用的是mysql数据库,表设计有26张。

​ 以上项目是本人自己设计编写的,如需源码请联系微信:wsjcql

image-20240721235415548
(img-TlekhLBS-1721612620461)]

​ 以上是基于Springboot的助农服务项目的介绍,运用到的技术和技术栈主要有springboot、mybaits、mybatisplus、redis、rabbitmq、elasticsearch、springsecurity、jwt令牌、springmail等等,同时自定义了一个基于物品的协同过滤算法,给用户做推荐。数据库使用的是mysql数据库,表设计有26张。

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值