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

基于springboot的助农服务平台

时间:2024-07-22 10:55:44浏览次数:6  
标签: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-20240719172816237

image-20240719172834076

image-20240719172902706

image-20240719172944577

image-20240719173021873

image-20240719173042078

image-20240719173105167

image-20240719173135890

image-20240719173158674

image-20240719173243927

![img](file:///C:/Users/Administrator/AppData/Roaming/Tencent/Users/491650652/QQ/WinTemp/RichOle/{6$AZ@82F@M685V2X@6]}}D.png)

image-20240721214832268

image-20240721214902277

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

image-20240721220344228

image-20240721220617122

image-20240721220643111

image-20240721220835056

image-20240721220915900

image-20240721220934903

image-20240721221015799

image-20240721221031563

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

标签:springboot,服务平台,request,private,String,xxlJobSpringExecutor,new,redisTemplate,助农
From: https://www.cnblogs.com/cqlwsj/p/18315608

相关文章

  • 毕业设计&毕业项目:基于springboot+vue实现的在线音乐平台
    一、前言        在当今数字化时代,音乐已经成为人们生活中不可或缺的一部分。随着技术的飞速发展,构建一个用户友好、功能丰富的在线音乐平台成为了许多开发者和创业者的目标。本文将介绍如何使用SpringBoot作为后端框架,结合Vue.js作为前端框架,共同实现一个高效、可扩展的......
  • 计算机Java项目|基于SpringBoot的高校办公室行政事务管理系统
    作者主页:编程指南针作者简介:Java领域优质创作者、CSDN博客专家、CSDN内容合伙人、掘金特邀作者、阿里云博客专家、51CTO特邀作者、多年架构师设计经验、多年校企合作经验,被多个学校常年聘为校外企业导师,指导学生毕业设计并参与学生毕业答辩指导,有较为丰富的相关经验。期待与......
  • A144-基于SpringBoot的大学生心理健康咨询系统(源码+数据库+文档+包运行)
    项目简介这是一个基于SpringBoot框架开发的在线心理测评管理系统,主要分为两个角色:管理员和用户。系统提供了一系列功能,旨在方便管理员和用户进行相关操作。管理员角色功能登录:管理员可以通过登录功能进入系统。首页展示:展示系统的概要信息或重要通知。文章管理:管理系统内的......
  • 基于springboot+vue的治安管理系统
    博主主页:猫头鹰源码博主简介:Java领域优质创作者、CSDN博客专家、阿里云专家博主、公司架构师、全网粉丝5万+、专注Java技术领域和毕业设计项目实战,欢迎高校老师\讲师\同行交流合作​主要内容:毕业设计(Javaweb项目|小程序|Python|HTML|数据可视化|SSM|SpringBoot|Vue|Jsp|PHP......
  • 基于协同过滤推荐算法+springboot+vue的校园二手商城(前后端分离)
    博主主页:猫头鹰源码博主简介:Java领域优质创作者、CSDN博客专家、公司架构师、全网粉丝5万+、专注Java技术领域和毕业设计项目实战主要内容:毕业设计(Javaweb项目|小程序等)、简历模板、学习资料、面试题库、技术咨询文末联系获取项目介绍: 本系统为原创项目,采用前后端分......
  • 免费【2024】springboot宝鸡文理学院学生成绩动态追踪系统
     博主介绍:✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌技术范围:SpringBoot、Vue、SSM、HTML、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app、大......
  • 免费【2024】springboot宝鸡文理学院学生成绩动态追踪系统
     博主介绍:✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌技术范围:SpringBoot、Vue、SSM、HTML、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app、大......
  • 免费【2024】springboot宝鸡文理学院学生成绩动态追踪系统
     博主介绍:✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌技术范围:SpringBoot、Vue、SSM、HTML、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app、大......
  • 免费分享一套SpringBoot+Vue高校心理咨询(心理教育辅导)系统【论文+源码+SQL脚本】,帅
    ​大家好,我是java1234_小锋老师,看到一个不错的SpringBoot+Vue高校心理咨询(心理教育辅导)系统,分享下哈。​项目视频演示【免费】SpringBoot+Vue高校心理咨询(心理教育辅导)系统Java毕业设计_哔哩哔哩_bilibili项目介绍随着Internet技术的发展,心理教育辅导系统应运而生,心......
  • 基于springboot的学生考勤管理系统
    博主介绍:java高级开发,从事互联网行业六年,熟悉各种主流语言,精通java、python、php、爬虫、web开发,已经做了多年的设计程序开发,开发过上千套设计程序,没有什么华丽的语言,只有实实在在的写点程序。......