記事ディレクトリ
1. 記事の序文
この記事の主な機能には、スポーツと健康のプラットフォームへのログインと登録、健康に関する知識の理解、スポーツ管理に関する記事と詳細の表示、毎日のログインとチェックイン、システム通知、メッセージ管理、スポーツ機能の送信が含まれます。サポート用のバックエンド言語として Java を使用するため、インターフェイスは使いやすく、開発は簡単です。
2. 開発プロセスとツールの準備
2.1. IntelliJ IDEA (バックエンド言語開発ツール)、Mysql データベース、および WeChat Web 開発者ツールをダウンロードしてインストールします。
3. 開発手順
1.Mavenプロジェクトの作成
まずSpringBootDemoという名前のプロジェクトを作成し、[新しいプロジェクト]を選択します
次に、下のポップアップ ウィンドウで、左側のメニューの [新しいプロジェクト] を選択します (注: 2022 年より前のバージョンのアイデアとは異なり、ここでは左側に [Maven] オプションがありません。[Maven Archetype] を選択しないでください。 )、Name (プロジェクト名): SpringBootDemo と入力し、言語として [java] を選択し、ビルド システムとして [maven] を選択して、jdk を選択します。ここでは jdk18 を選択しました。
次に、[作成]をクリックします。
2.プロジェクト配下にモジュールを作成
右クリックして
左側の[新規]-[モジュール...]を選択し、[Spring initializr]を選択すると、ideaに統合されているSpring initializrツールを介してSpring Bootプロジェクトをすばやく作成できます。ウィンドウの右側: 名前は独自の設定に従って設定できます。グループとアーティファクトには上記と同じルールがあり、他のオプションはデフォルト値を維持できます。[次へ]
Developer Toolsモジュールは[Spring Boot DevTools]、Webモジュールは[Spring Web]を確認してください。
この時点で、Springboot プロジェクトが構築され、後続の機能を開発できるようになります。
3. モーションエンティティクラス、Mapper、およびサービスを作成します (3 層アーキテクチャ)
@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. モーション管理コントローラークラスを作成します。
@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を作成したいため、コントローラーに@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 フレームワークを初めて使用する初心者にもフレンドリーであり、小さなプログラムを初めて使用するユーザーにもフレンドリーです。プロジェクト リソースが大きすぎるため、ブロガーにプライベート メッセージを送信してプロジェクトを取得できます。