首页 > 其他分享 >基于springboot的助农服务平台

基于springboot的助农服务平台

时间:2024-07-24 12:01:16浏览次数:8  
标签:springboot 服务平台 request private String xxlJobSpringExecutor new redisTemplate 助农

基于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
新增商品表单

新增权限控制表单
新增店铺表单

用户端页面如下图所示,采用的是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张。

标签:springboot,服务平台,request,private,String,xxlJobSpringExecutor,new,redisTemplate,助农
From: https://blog.csdn.net/weixin_50020009/article/details/140601218

相关文章

  • 基于Java+SpringBoot+Vue的精品在线试题库系统的设计与开发(源码+lw+部署文档+讲解等)
    文章目录前言项目背景介绍技术栈后端框架SpringBoot前端框架Vue数据库MySQL(MyStructuredQueryLanguage)具体实现截图详细视频演示系统测试系统测试目的系统功能测试系统测试结论代码参考数据库参考源码获取前言......
  • 【超实用攻略】SpringBoot + validator 轻松实现全注解式的参数校验
    一、故事背景关于参数合法性验证的重要性就不多说了,即使前端对参数做了基本验证,后端依然也需要进行验证,以防不合规的数据直接进入服务器,如果不对其进行拦截,严重的甚至会造成系统直接崩溃!本文结合自己在项目中的实际使用经验,主要以实用为主,对数据合法性验证做一次总结,不了解的朋......
  • springboot属性统一配置,分层级
    app.user.name=JohnDoeapp.user.age=30app.user.address.city=NewYorkapp.user.address.country=USAimportorg.springframework.boot.context.properties.ConfigurationProperties;importorg.springframework.context.annotation.Configuration;@Configuration......
  • SpringBoot整合SSE技术详解
    SpringBoot整合SSE技术详解1.引言在现代Web应用中,实时通信变得越来越重要。Server-SentEvents(SSE)是一种允许服务器向客户端推送数据的技术,为实现实时更新提供了一种简单而有效的方法。本文将详细介绍如何在SpringBoot中整合SSE,并探讨SSE与WebSocket的区别。2.SS......
  • 基于SpringBoot+Vue+uniapp的企业人才引进服务平台的详细设计和实现(源码+lw+部署文档
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • springboot学习笔记 1 - Spring Boot 简介
    SpringBoot学习笔记什么是SpringBootSpringBoot的特点SpringBoot与Spring的区别开发环境要求使用SpringInitializr创建项目构建并运行第一个SpringBoot应用代码示例总结什么是SpringBoot大家好,欢迎来到“SpringBoot学习笔记”系列。首先,让我们从一个简单......
  • springboot 使用 rocketMQ
    POM依赖<dependency><groupId>org.apache.rocketmq</groupId><artifactId>rocketmq-spring-boot-starter</artifactId><version>2.2.2</version></dependency>配置文件rocketmq:name-server:192.168.20......
  • 计算机编程—IT实战课堂 Springboot 电竞兴趣论坛系统
    计算机编程—IT实战课堂:Springboot电竞兴趣论坛系统随着电子竞技行业的迅猛发展,电竞爱好者对于交流平台的需求日益增长。结合IT实战课堂的教学实践,我们利用SpringBoot框架开发了一款集讨论、资源共享、赛事追踪于一体的电竞兴趣论坛系统。本文将深入探讨该项目的构思背景、......
  • 创建SpringBoot项目时出现Cannot resolve plugin org.springframework的解决方法 原
    创建SpringBoot项目时出现Cannotresolvepluginorg.springframework的解决方法原因是添加依赖时未添加版本号原因是添加依赖时未添加版本号解决方法:在pom.xml文件中的依赖添加版本号原来:<plugin><groupId>org.springframework.boot</groupId><a......
  • java毕业设计-基于微信小程序的蛋糕订购商城系统设计与实现,基于springboot+vue+微信小
    文章目录前言演示视频项目背景项目架构和内容获取(文末获取)具体实现截图用户微信小程序端管理后台技术栈具体功能模块设计系统需求分析可行性分析系统测试为什么我?关于我我自己的网站项目相关文件前言博主介绍:✌️码农一枚,专注于大学生项目实战开发、讲解和毕业......