From 81ccdecb9f2d3813e907779630065eda66ad1679 Mon Sep 17 00:00:00 2001 From: huang <2304647919@qq.com> Date: Wed, 3 May 2023 11:35:49 +0800 Subject: [PATCH] qianduan --- front/.gitignore | 14 ++ front/.idea/.name | 1 + front/.idea/codeStyles/Project.xml | 116 ++++++++++++ front/.idea/compiler.xml | 6 + front/.idea/gradle.xml | 16 ++ front/.idea/misc.xml | 23 +++ front/.idea/runConfigurations.xml | 12 ++ front/app/.gitignore | 1 + front/app/build.gradle | 35 ++++ front/app/proguard-rules.pro | 21 +++ .../ExampleInstrumentedTest.java | 27 +++ front/app/src/main/AndroidManifest.xml | 25 +++ .../example/myapplication/MainActivity.java | 155 ++++++++++++++++ .../myapplication/model/dao/Constant.java | 10 + .../myapplication/model/entity/User.java | 22 +++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable/ic_launcher_background.xml | 170 +++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 79 ++++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes front/app/src/main/res/values/colors.xml | 6 + front/app/src/main/res/values/strings.xml | 3 + front/app/src/main/res/values/styles.xml | 11 ++ .../main/res/xml/network_security_config.xml | 4 + .../myapplication/ExampleUnitTest.java | 17 ++ front/build.gradle | 27 +++ front/gradle.properties | 20 ++ front/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + front/gradlew | 172 ++++++++++++++++++ front/gradlew.bat | 84 +++++++++ front/settings.gradle | 2 + 42 files changed, 1129 insertions(+) create mode 100644 front/.gitignore create mode 100644 front/.idea/.name create mode 100644 front/.idea/codeStyles/Project.xml create mode 100644 front/.idea/compiler.xml create mode 100644 front/.idea/gradle.xml create mode 100644 front/.idea/misc.xml create mode 100644 front/.idea/runConfigurations.xml create mode 100644 front/app/.gitignore create mode 100644 front/app/build.gradle create mode 100644 front/app/proguard-rules.pro create mode 100644 front/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java create mode 100644 front/app/src/main/AndroidManifest.xml create mode 100644 front/app/src/main/java/com/example/myapplication/MainActivity.java create mode 100644 front/app/src/main/java/com/example/myapplication/model/dao/Constant.java create mode 100644 front/app/src/main/java/com/example/myapplication/model/entity/User.java create mode 100644 front/app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 front/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 front/app/src/main/res/layout/activity_main.xml create mode 100644 front/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 front/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 front/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 front/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 front/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 front/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 front/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 front/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 front/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 front/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 front/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 front/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 front/app/src/main/res/values/colors.xml create mode 100644 front/app/src/main/res/values/strings.xml create mode 100644 front/app/src/main/res/values/styles.xml create mode 100644 front/app/src/main/res/xml/network_security_config.xml create mode 100644 front/app/src/test/java/com/example/myapplication/ExampleUnitTest.java create mode 100644 front/build.gradle create mode 100644 front/gradle.properties create mode 100644 front/gradle/wrapper/gradle-wrapper.jar create mode 100644 front/gradle/wrapper/gradle-wrapper.properties create mode 100644 front/gradlew create mode 100644 front/gradlew.bat create mode 100644 front/settings.gradle diff --git a/front/.gitignore b/front/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/front/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/front/.idea/.name b/front/.idea/.name new file mode 100644 index 0000000..557ddab --- /dev/null +++ b/front/.idea/.name @@ -0,0 +1 @@ +jesus \ No newline at end of file diff --git a/front/.idea/codeStyles/Project.xml b/front/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/front/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/front/.idea/compiler.xml b/front/.idea/compiler.xml new file mode 100644 index 0000000..38d573b --- /dev/null +++ b/front/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/front/.idea/gradle.xml b/front/.idea/gradle.xml new file mode 100644 index 0000000..d291b3d --- /dev/null +++ b/front/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/front/.idea/misc.xml b/front/.idea/misc.xml new file mode 100644 index 0000000..1a45ef3 --- /dev/null +++ b/front/.idea/misc.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + Android + + + + + + + + + + + \ No newline at end of file diff --git a/front/.idea/runConfigurations.xml b/front/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/front/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/front/app/.gitignore b/front/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/front/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/front/app/build.gradle b/front/app/build.gradle new file mode 100644 index 0000000..dccc457 --- /dev/null +++ b/front/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.example.myapplication" + minSdkVersion 23 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.squareup.okhttp3:okhttp:4.2.2' + implementation 'com.alibaba:fastjson:1.2.62' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/front/app/proguard-rules.pro b/front/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/front/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/front/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java b/front/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java new file mode 100644 index 0000000..af71346 --- /dev/null +++ b/front/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.example.myapplication; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.example.myapplication", appContext.getPackageName()); + } +} diff --git a/front/app/src/main/AndroidManifest.xml b/front/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1a66719 --- /dev/null +++ b/front/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/front/app/src/main/java/com/example/myapplication/MainActivity.java b/front/app/src/main/java/com/example/myapplication/MainActivity.java new file mode 100644 index 0000000..384a91d --- /dev/null +++ b/front/app/src/main/java/com/example/myapplication/MainActivity.java @@ -0,0 +1,155 @@ +package com.example.myapplication; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.os.Looper; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.alibaba.fastjson.JSONArray; +import com.example.myapplication.model.dao.*; +import com.example.myapplication.model.entity.*; + +import java.io.IOException; +import java.util.List; + +import okhttp3.FormBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Button register = findViewById(R.id.register); + register.setOnClickListener( + v -> + { + new Thread(()-> { + OkHttpClient okHttpClient = new OkHttpClient(); + String name = ((EditText) findViewById(R.id.name)).getText().toString(); + FormBody formBody = new FormBody.Builder().add("name", name).build(); + Request request = new Request.Builder() + .url(Constant.ADD) + .post(formBody) + .build(); + try (Response response = okHttpClient.newCall(request).execute()) { + Looper.prepare(); + if (Boolean.parseBoolean(response.body().string())) + { + Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show(); + } + else + { + Toast.makeText(this, "注册失败", Toast.LENGTH_SHORT).show(); + } + Looper.loop(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + } + ); + Button login = findViewById(R.id.login); + login.setOnClickListener( + v -> + { + new Thread(()-> { + OkHttpClient okHttpClient = new OkHttpClient(); + String name = ((EditText) findViewById(R.id.name)).getText().toString(); + FormBody formBody = new FormBody.Builder().add("name", name).build(); + Request request = new Request.Builder() + .url(Constant.GET) + .post(formBody) + .build(); + try (Response response = okHttpClient.newCall(request).execute()) { + List users = JSONArray.parseArray(response.body().string(),User.class); + Looper.prepare(); + if(users.size() == 0) + { + Toast.makeText(this,"登录失败",Toast.LENGTH_SHORT).show(); + } + else + { + Toast.makeText(this,"登录成功",Toast.LENGTH_SHORT).show(); + } + Looper.loop(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + } + ); + + Button delete = findViewById(R.id.delete); + delete.setOnClickListener( + v -> + { + new Thread(()-> { + OkHttpClient okHttpClient = new OkHttpClient(); + String name = ((EditText) findViewById(R.id.name)).getText().toString(); + FormBody formBody = new FormBody.Builder().add("name", name).build(); + Request request = new Request.Builder() + .url(Constant.DELETE) + .post(formBody) + .build(); + try (Response response = okHttpClient.newCall(request).execute()) { + Looper.prepare(); + if (Boolean.parseBoolean(response.body().string())) + { + Toast.makeText(this, "删除成功", Toast.LENGTH_SHORT).show(); + } + else + { + Toast.makeText(this, "删除失败", Toast.LENGTH_SHORT).show(); + } + Looper.loop(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + } + ); + + Button modify = findViewById(R.id.modify); + modify.setOnClickListener( + v -> + { + new Thread(()-> { + OkHttpClient okHttpClient = new OkHttpClient(); + String name = ((EditText) findViewById(R.id.name)).getText().toString(); + String id = ((EditText)findViewById(R.id.id)).getText().toString(); + FormBody formBody = new FormBody.Builder() + .add("name", name) + .add("id",id) + .build(); + Request request = new Request.Builder() + .url(Constant.MODIFY) + .post(formBody) + .build(); + try (Response response = okHttpClient.newCall(request).execute()) { + Looper.prepare(); + if (Boolean.parseBoolean(response.body().string())) + { + Toast.makeText(this, "修改成功", Toast.LENGTH_SHORT).show(); + } + else + { + Toast.makeText(this, "修改失败", Toast.LENGTH_SHORT).show(); + } + Looper.loop(); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + } + ); + } +} diff --git a/front/app/src/main/java/com/example/myapplication/model/dao/Constant.java b/front/app/src/main/java/com/example/myapplication/model/dao/Constant.java new file mode 100644 index 0000000..a94f5d4 --- /dev/null +++ b/front/app/src/main/java/com/example/myapplication/model/dao/Constant.java @@ -0,0 +1,10 @@ +package com.example.myapplication.model.dao; + +public class Constant { + private final static String BASE_URL = "http://192.168.0.107:8080/demo/"; + public final static String ADD = BASE_URL+"add"; + public final static String GET = BASE_URL+"get"; + public final static String GETALL = BASE_URL+"getAll"; + public final static String DELETE = BASE_URL+"delete"; + public final static String MODIFY = BASE_URL+"modify"; +} diff --git a/front/app/src/main/java/com/example/myapplication/model/entity/User.java b/front/app/src/main/java/com/example/myapplication/model/entity/User.java new file mode 100644 index 0000000..35e9842 --- /dev/null +++ b/front/app/src/main/java/com/example/myapplication/model/entity/User.java @@ -0,0 +1,22 @@ +package com.example.myapplication.model.entity; + +public class User { + private Integer id; + private String name; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/front/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/front/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/front/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/front/app/src/main/res/drawable/ic_launcher_background.xml b/front/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/front/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/front/app/src/main/res/layout/activity_main.xml b/front/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..43492ab --- /dev/null +++ b/front/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,79 @@ + + + +