基于Springboot+Mybatis+微信小程序实现小型运动管理平台


一、文章前言

此文主要功能包括:运动健康平台登录注册、了解健康知识、查看管理运动的文章与详情、每日登录打卡、系统通知、留言管理、提交运动功能。使用Java作为后端语言进行支持,界面友好,开发简单。

二、开发流程及工具准备

2.1、下载安装IntelliJ IDEA(后端语言开发工具),Mysql数据库,微信Web开发者工具。

三、开发步骤

1.创建maven project

先创建一个名为SpringBootDemo的项目,选择【New Project】
在这里插入图片描述

然后在弹出的下图窗口中,选择左侧菜单的【New Project】(注:和2022之前的idea版本不同,这里左侧没有【Maven】选项,不要选【Maven Archetype】!!!),输入Name(项目名):SpringBootDemo,language选择【java】,build system选择【maven】,然后选择jdk,我这里选的是jdk18.

在这里插入图片描述然后点击【Create】
在这里插入图片描述

2.在project下创建module

点击右键选择【new】—【Module…】
在这里插入图片描述
左侧选择【Spring initializr】,通过idea中集成的Spring initializr工具进行spring boot项目的快速创建。窗口右侧:name可根据自己喜好设置,group和artifact和上面一样的规则,其他选项保持默认值即可,【next】
在这里插入图片描述

Developer Tools模块勾选【Spring Boot DevTools】,web模块勾选【Spring Web】

在这里插入图片描述

此时,一个Springboot项目已经搭建完成,可开发后续功能

3.编写一个运动实体类、Mapper、service(三层架构)

@Data
public class Motion {

    //运动记录id
    @TableId(type = IdType.AUTO)
    private Long id;

    //运动类型id
    private Integer typeId;

    //类型
    private Integer type;

    //用户id
    private Long userId;

    //运动分数
    private int num;

    //创建使劲
    private LocalDateTime createTime;

    //运动内容
    private String content;

}

由于我们使用mybatis-plus,所以简单的增删改查不用自己写,框架自带了,只需要实现或者继承他的Mapper、Service
在这里插入图片描述

4.编写运动管理Controller类

@RestController
@RequestMapping("motion")
public class MotionController {

    @Autowired
    private MotionMapper motionMapper;


    @Autowired
    private MotionTypeMapper motionTypeMapper;


    @Autowired
    private UserMapper userMapper;


    //查询列表
    @PostMapping("selectPage")
    public Map selectPage(@RequestBody Motion motion, Integer pageSize, Integer pageNum) {
        ReturnMap returnMap = new ReturnMap();
        //分页需要的Page
        Page<Motion> page = new Page<>();
        page.setCurrent(pageNum + 1);
        page.setSize(pageSize);
        QueryWrapper<Motion> queryWrapper = new QueryWrapper<>();
        //可根据条件模糊查询
        Page<Motion> selectPage = motionMapper.selectPage(page, queryWrapper.lambda()
                .eq(motion.getTypeId() != null, Motion::getTypeId, motion.getTypeId())

                .orderByDesc(Motion::getCreateTime));

        List<Motion> list = selectPage.getRecords();
        for (Motion data : list) {
            MotionType motionType = motionTypeMapper.selectById(data.getTypeId());
            data.setTypeName(motionType != null ? motionType.getTitle() : "");
            User user = userMapper.selectById(data.getUserId());
            data.setUserName(user != null ? user.getNickname() : "");
        }
        selectPage.setRecords(list);
        returnMap.setData("page", selectPage);
        return returnMap.getreturnMap();
    }


    //查询用于运动积分查询列表
    @PostMapping("list")
    public Map selectPage(Long userId) {
        ReturnMap returnMap = new ReturnMap();
        QueryWrapper<Motion> queryWrapper = new QueryWrapper<>();
        List<Motion> list = motionMapper.selectList
                (queryWrapper.lambda().eq(Motion::getUserId, userId).orderByDesc(Motion::getCreateTime));
        int integralSum = 0;
        for (Motion motion1 : list) {
            MotionType motionType = motionTypeMapper.selectById(motion1.getTypeId());
            if (motion1.getType() == 1) {
                motion1.setTitle("签到");
            } else {
                motion1.setTitle(motionType != null ? motionType.getTitle() : "");
            }
            motion1.setTypeName(motionType != null ? motionType.getTitle() : "");
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            motion1.setTimeCreate(simpleDateFormat.format(Date.from(motion1.getCreateTime().atZone(ZoneId.systemDefault()).toInstant())));
            integralSum += motion1.getNum();

        }
        returnMap.setData("integralSum", integralSum);
        returnMap.setData("list", list);
        return returnMap.getreturnMap();
    }

因为要编写Rest风格的Api,要在Controller上标注@RestController注解

5.编写小程序相关代码

文章列表:

<view class="cu-bar bg-white solid-bottom">
    <view class="action">
      <text class="cuIcon-title text-blue"></text>文章列表
    </view>
  </view>
<view class="cu-card article no-card " wx:for="{{articleList}}" wx:key="{{index}}" bindtap="showModal" data-target="Modal" data-index="{{index}}">
  <view class="cu-item shadow">
    <view class="title">
      <view class="text-cut">{{item.title}}</view>
    </view>
    <view class="content">
      <image src="{{item.image}}" mode="aspectFill"></image>
      <view class="desc">
        <view class="text-content">{{item.content}}</view>
        <view>
          <view class="cu-tag bg-green light sm round">{{item.icon}}</view>
        </view>
      </view>
    </view>
  </view>
</view>

签到功能:

<view class="cu-bar bg-white solid-bottom">
    <view class="action">
      <text class="cuIcon-title text-green"></text>当前积分:{{integralSum}}
    </view>
    <view class="action" bindtap="signIn" >
      <text class="cuIcon-roundadd text-green">签到</text>
    </view>
  </view>

  <view class="cu-list menu {{menuBorder?'sm-border':''}} {{menuCard?'card-menu margin-top':''}}">
    <view class="cu-item" wx:for="{{integralRecord}}" wx:key="{{index}}">
      <view class="content padding-tb-sm">
        <view>
          <text class="cuIcon-footprint text-green margin-right-xs"></text> {{item.title}}</view>
        <view class="text-gray text-sm">
          <text class="cuIcon-time margin-right-xs"></text> {{item.timeCreate}}</view>
      </view>
      <view class="action">
        +{{item.num}}
      </view>
    </view>
  </view>

该项目对于初学Springboot框架友好,也对刚入门小程序的小白友好。因项目资源过大,可私信博主获取项目。

  • 37
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
如果您下载了本程序,但是该程序存在问题无法运行,那么您可以选择退款或者寻求我们的帮助(如果找我们帮助的话,是需要追加额外费用的)。另外,您不会使用资源的话(这种情况不支持退款),也可以找我们帮助(需要追加额外费用) 随着移动互联网技术的发展和用户需求的变化,【小程序名称】应运而生,以其轻量化、便捷化的设计理念为用户提供了一种全新的服务模式。作为一款无需下载安装即可使用的应用,【小程序名称】依托于微信庞大的生态系统,让用户在微信内就能轻松实现各种功能操作。 【小程序名称】的核心功能主要集中在【具体服务领域】,例如在线购物、本地生活服务、教育学习或健康管理等。它简化了传统APP繁琐的注册登录流程,支持微信一键授权登录,极大地提升了用户体验。用户通过搜索或扫描二维码,瞬间即可开启使用,享受快速加载、流畅运行的服务。 该小程序界面设计简洁明了,布局合理,易于上手。同时,其特色功能如实时更新的信息推送、个性化推荐以及社交分享功能,让用户能够及时获取所需信息,并方便地将优质内容分享至朋友圈或好友,实现信息的高效传播与互动。 【小程序名称】注重数据安全与隐私保护,严格遵守国家法律法规和微信平台的规定,确保用户数据的安全无虞。此外,其背后的开发团队持续迭代更新,根据用户反馈不断优化产品性能,提升服务质量,致力于打造一个贴近用户需求、充满活力的小程序生态。 总结来说,【小程序名称】凭借其小巧便携、快捷高效的特性,不仅节省了用户的手机存储空间,更为用户提供了无缝衔接的便利服务,是现代生活中不可或缺的一部分,真正实现了“触手可及”的智能生活新体验。只需轻点屏幕,无限精彩尽在掌握之中。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

无语小咪

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

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

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

打赏作者

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

抵扣说明:

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

余额充值