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 @@ + + + +