学习进度条

今日所花时间:一小时
今日代码量:100行
博客量:一篇
了解到的知识点: 深入学习androidStudio 完成学习记录APP开发
完成AndroidStudio代码

在build.gradle.kts添加依赖

dependencies {
    implementation(libs.appcompat)
    implementation(libs.material)
    implementation(libs.activity)
    implementation(libs.constraintlayout)
    testImplementation(libs.junit)
    androidTestImplementation(libs.ext.junit)
    androidTestImplementation(libs.espresso.core)
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
    implementation("androidx.recyclerview:recyclerview:1.3.2")
}

创建modules(写实体类代码)

User

package com.example.study0327.modules;

public class User {
    private String studentId;
    private String username;
    private String phone;
    private String className;
    private String unit;
    private String password;

    // 构造函数、getter和setter

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User() {
    }

    public User(String studentId, String username, String phone, String className, String unit, String password) {
        this.studentId = studentId;
        this.username = username;
        this.phone = phone;
        this.className = className;
        this.unit = unit;
        this.password = password;
    }


}

DailySummary

package com.example.study0327.modules;

public class DailySummary {
    private Integer userId;
    private String summaryDate;
    private String blogUrl;

    // 构造函数、getter和setter

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getSummaryDate() {
        return summaryDate;
    }

    public void setSummaryDate(String summaryDate) {
        this.summaryDate = summaryDate;
    }

    public String getBlogUrl() {
        return blogUrl;
    }

    public void setBlogUrl(String blogUrl) {
        this.blogUrl = blogUrl;
    }
}

ProgrammingRecord

package com.example.study0327.modules;

public class ProgrammingRecord {
    private Integer userId;
    private String recordDate;
    private String pspStage;
    private String content;
    private Integer timeSpent;

    // 构造函数、getter和setter

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getRecordDate() {
        return recordDate;
    }

    public void setRecordDate(String recordDate) {
        this.recordDate = recordDate;
    }

    public String getPspStage() {
        return pspStage;
    }

    public void setPspStage(String pspStage) {
        this.pspStage = pspStage;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getTimeSpent() {
        return timeSpent;
    }

    public void setTimeSpent(Integer timeSpent) {
        this.timeSpent = timeSpent;
    }
}

WeekGoal

package com.example.study0327.modules;

public class WeeklyGoal {
    private Integer userId;
    private String goalContent;
    private String weekStartDate;

    // 构造函数、getter和setter

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getGoalContent() {
        return goalContent;
    }

    public void setGoalContent(String goalContent) {
        this.goalContent = goalContent;
    }

    public String getWeekStartDate() {
        return weekStartDate;
    }

    public void setWeekStartDate(String weekStartDate) {
        this.weekStartDate = weekStartDate;
    }
}

创建与后端的连接

ApiService

package com.example.study0327.api;

import com.example.study0327.modules.DailySummary;
import com.example.study0327.modules.ProgrammingRecord;
import com.example.study0327.modules.User;
import com.example.study0327.modules.WeeklyGoal;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Query;

public interface ApiService {
    @POST("/user/register")
    Call<String> registerUser(@Body User user);

    @POST("/user/login")
    Call<String> loginUser(@Query("studentId") String studentId, @Query("password") String password);


    @POST("/weeklyGoal/setGoal")
    Call<String> setWeeklyGoal(@Body WeeklyGoal weeklyGoal);

    @POST("/dailySummary/addSummary")
    Call<String> addDailySummary(@Body DailySummary dailySummary);

    @POST("/programmingRecord/addRecord")
    Call<String> addProgrammingRecord(@Body ProgrammingRecord programmingRecord);
}

RetrofitClient

package com.example.study0327.api;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitClient {
    private static final String BASE_URL = "http://192.168.188.118:8080/";
    private static Retrofit retrofit = null;

    public static Retrofit getClient() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }
}

posted @ 2025-03-26 19:10  haoyinuo  阅读(12)  评论(0)    收藏  举报