您的位置:首页 > 其它

一个简单的学生成绩管理系统(我的第一篇博客)

2019-07-20 15:04 274 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_41996971/article/details/96593215

学生成绩管理系统Demo,android+servlet(前端+后台)

一个简单的学生成绩管理系统

Hello,这还是自己第一次写博客,有点小激动~
一个完美的系统的展现是源于知识的积累沉淀,感觉自己还是个android知识小白,虽然这个管理系统不是那么完善,但是也花了一些时间,分享给大家,请大家多多指教哈~
我这次使用的是androidstudio和intelliJ IDES,这个系统分为教师和学生登录,我暂时完成了教师端的一些功能。后台servlet连接了数据库
以下展示后台代码目录和android代码目录和mysql
(1)后台代码目录
(2)android代码目录(学生端代码没有实现,不展示了)
(3)数据库五个表

android端代码如下

首先来看看我们的登录注册吧
先展示一下下图片哈~

代码如下:
(1)Register1Activity:
package com.example.management;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.management.Student.StudentHomePageActivity;

import com.example.management.Utils.StatusbarUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class Register1Activity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener{

public static final int Teacher_OPTION = 1;
public static final int Student_OPTION = 2;
private String str_username = "";//获取用户名
private String str_password = "";//用户密码

private EditText editText_accountr;//注意实例化的位置
private EditText editText_passwordr;//

private Button register;
private Button jumpToMainr;
private RadioGroup radio_group;
private String code;//服务器返回的值
int flag = 0;
int time;
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
//Log.d("123456", "handleMessage: "+msg.obj.toString());
code = jsonToJsonObject(msg.obj.toString());
Log.d("hander", "code: "+code);
if (code.equals("0")) {//登录成功,跳转主页面
//                MainActivity.isLogin = true;
//保存当前信息
Log.d("handler", "登录成功");
//                Bundle bundle = new Bundle();
//                bundle.putString("id", id);
//                bundle.putString("account", str_username);
//                bundle.putString("password", str_password);
//                bundle.putInt("option", msg.arg1);
//                bundle.putBoolean("status", true);
//                UserInfoUtil.saveCurrentInfo(getApplicationContext(), bundle);
Toast.makeText(Register1Activity.this, "注册成功", Toast.LENGTH_SHORT).show();

if(flag==Teacher_OPTION){
Intent intent1 = new Intent(Register1Activity.this, TeacherHomePageActivity.class);
startActivity(intent1);
}else if(flag==Student_OPTION){
Intent intent = new Intent(Register1Activity.this, StudentHomePageActivity.class);
startActivity(intent);
}
//finish();
} else if(code.equals("-1")){//若注册失败,清空输入框,提醒用户重新俗人
Toast.makeText(Register1Activity.this, "账号已存在!", Toast.LENGTH_SHORT).show();
editText_accountr.setText("");
editText_passwordr.setText("");
}else if(code.equals("-2")){
Toast.makeText(Register1Activity.this, "系统繁忙,稍后重试!", Toast.LENGTH_SHORT).show();
editText_accountr.setText("");
editText_passwordr.setText("");
}
return true;
}
});

public String jsonToJsonObject(String json) {
Log.d("hello", "jsonToJsonObject: " + json);
String code = "";
String message = null;
try {
JSONObject jsonObject = new JSONObject(json);
code = jsonObject.optString("code");
// message = jsonObjec
7ff7
t.optString("message");
} catch (JSONException e) {
e.printStackTrace();
}
return code;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register1);
initView();
}

/***
*布局初始化
*/
private void initView() {

StatusbarUtil.setTransparentWindow(this, false);
register = findViewById(R.id.register_btn);
editText_accountr = findViewById(R.id.account_register);//须再onCreate里实例化
editText_passwordr = findViewById(R.id.password_register);//须再onCreate里实例化
jumpToMainr = findViewById(R.id.jumpToMainr);
radio_group = findViewById(R.id.radio_group);

register.setOnClickListener(this);
jumpToMainr.setOnClickListener(this);
radio_group.setOnCheckedChangeListener(this);
}

private void sendRequestWithOkHttp() {

str_username = editText_accountr.getText().toString();//getText()要放到监听里面//获取用户名
str_password = editText_passwordr.getText().toString();//获取用户密码

new Thread(new Runnable() {
@Override
public void run() {
try {

if (flag == Teacher_OPTION) {
Log.d("mode", "run: " + flag);
requestNet(str_password, "http://10.161.66.7:8080/three/servlet/RegisterTeacherServlet?", Teacher_OPTION);
} else if (flag == Student_OPTION) {
Log.d("mode", "run: " + flag);
requestNet(str_password, "http://10.161.66.7:8080/three/servlet/RegisterStudentServlet?", Student_OPTION);
}

} catch (Exception e) {
e.printStackTrace();
}
}
}).start();

}

/***
*联网注册请求
*@return void
*@author zmj
*created at 2019/3/20 18:50
*/
private void requestNet(String finalStr_password_MD, String s, int option) throws IOException {

OkHttpClient client = new OkHttpClient();
RequestBody responseBody = null;
if (option == Teacher_OPTION) {
responseBody = new FormBody.Builder().add("no", str_username).add("password", finalStr_password_MD).build();
} else if (option == Student_OPTION) {
//Log.d("123456", "requestNet: "+123456);
responseBody = new FormBody.Builder().add("no", str_username).add("password", finalStr_password_MD).build();
// Log.d("responsd", responseBody.toString());
}

Request request = new Request.Builder().url(s).post(responseBody).build();
Call call = client.newCall(request);
Response response = call.execute();
Message message = handler.obtainMessage();
message.obj = response.body().string();
message.arg1 = option;
handler.sendMessage(message);
Log.d("requestNet", (String) message.obj+message.arg1);

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.register_btn:

sendRequestWithOkHttp();
break;
case R.id.jumpToMainr: {
Intent intent = new Intent(Register1Activity.this, LoginActivity.class);
startActivity(intent);
break;
}

}

}

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
flag = 0;
switch (checkedId) {
case R.id.teacherR:
flag = 1;
break;
case R.id.studentR:
flag = 2;
break;
}
}

}

(2)LoginActivity
package com.example.management;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.management.Student.StudentHomePageActivity;

import com.example.management.Utils.StatusbarUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener{

public static final int Teacher_OPTION = 1;
public static final int Student_OPTION = 2;
private String id;//获取用户id
private String str_username = "";//获取用户名
private String str_password = "";//用户密码
private String code;//服务器返回的值

private EditText accountEditl;
private EditText passwordEditl;
private Button login;

private Button jumpToRegister;
private Button back;
private RadioGroup radio_group_login;
public static int flag;

private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
//Log.d("123456", "handleMessage: "+msg.obj.toString());
code = jsonToJsonObject(msg.obj.toString());
Log.d("hander", "code: "+code);
if (code.equals("0")) {
//                MainActivity.isLogin = true;
//保存当前信息
Log.d("handler", "登录成功");
//                Bundle bundle = new Bundle();
//                bundle.putString("id", id);
//                bundle.putString("account", str_username);
//                bundle.putString("password", str_password);
//                bundle.putInt("option", msg.arg1);
//                bundle.putBoolean("status", true);
//                UserInfoUtil.saveCurrentInfo(getApplicationContext(), bundle);
Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
if(flag==Teacher_OPTION){
Intent intent1 = new Intent(LoginActivity.this, TeacherHomePageActivity.class);
startActivity(intent1);
}else if(flag==Student_OPTION){
Intent intent = new Intent(LoginActivity.this, StudentHomePageActivity.class);
startActivity(intent);
}

//finish();
} else if(code.equals("-1")){//若账号不存在,跳转至注册页面
Toast.makeText(LoginActivity.this, "登录失败,请先注册", Toast.LENGTH_SHORT).show();
accountEditl.setText("");
passwordEditl.setText("");
Intent intent = new Intent(LoginActivity.this, Register1Activity.class);
startActivity(intent);
}
return true;
}
});

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
StatusbarUtil.setTransparentWindow(this, false);

initView();
}

/***
*初始化布局
*@param
*@return void
*@author
*created at 2019/3/19 23:13
*/

private void initView() {
//        MainActivity.isLogin = false;
accountEditl = findViewById(R.id.accountl);
passwordEditl = findViewById(R.id.passwordl);
login = findViewById(R.id.login_btn);
//back = findViewById(R.id.jumpToMainl);
radio_group_login = findViewById(R.id.radio_group_login);
jumpToRegister = findViewById(R.id.jumpToRegister);

login.setOnClickListener(this);
jumpToRegister.setOnClickListener(this);
//back.setOnClickListener(this);
radio_group_login.setOnCheckedChangeListener(this);
}

@Override
public void onClick(View v) {

switch (v.getId()) {
case R.id.login_btn:
sendRequestWithOkHttp();
break;
case R.id.jumpToRegister:
Intent intent1 = new Intent(LoginActivity.this, Register1Activity.class);
startActivity(intent1);
break;
//            case R.id.jumpToMainl:
//                Intent intent2 = new Intent(LoginActivity.this, MainActivity.class);
//                startActivity(intent2);
//                break;
}

}

private void sendRequestWithOkHttp() {
str_username = accountEditl.getText().toString();//getText()要放到监听里面
str_password = passwordEditl.getText().toString();

//密码进行加密
//        String str_password_MD5 = "";
//        str_password_MD5 = MD5Utils.encode(str_password);
//        final String finalStr_password_MD = str_password_MD5;

new Thread(new Runnable() {
@Override
public void run() {
//Log.d("123456", "run: " + flag);
try {
if (flag == Teacher_OPTION) {
requestNet(str_password, "http://10.161.66.7:8080/three/servlet/LoginTeacherServlet?", Teacher_OPTION);
} else if (flag == Student_OPTION) {
requestNet(str_password, "http://10.161.66.7:8080/three/servlet/LoginStudentServlet?", Student_OPTION);
Log.d("send:  ", "http://10.161.66.7:8080/three/servlet/LoginStudentServlet?");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

/***
*网络请求
*@return void
*@author wenhaoz
*created at 2019/3/19 23:17
*/
private void requestNet(String finalStr_password_MD, String s, int option) throws IOException {

OkHttpClient client = new OkHttpClient();
RequestBody responseBody = null;
if (option == Teacher_OPTION) {
responseBody = new FormBody.Builder().add("no", str_username).add("password", finalStr_password_MD).build();
} else if (option == Student_OPTION) {
//Log.d("123456", "requestNet: "+123456);
responseBody = new FormBody.Builder().add("no", str_username).add("password", finalStr_password_MD).build();
// Log.d("responsd", responseBody.toString());
}

Request request = new Request.Builder().url(s).post(responseBody).build();
Call call = client.newCall(request);
Response response = call.execute();
Message message = handler.obtainMessage();
message.obj = response.body().string();
message.arg1 = option;
handler.sendMessage(message);
Log.d("requestNet", (String) message.obj+message.arg1);
}

/***
*解析状态码
*@return java.lang.String
*@author wenhaoz
*created at 2019/3/19 23:18
*/
public String jsonToJsonObject(String json) {
Log.d("hello", "jsonToJsonObject: " + json);
String code = "";
String message = null;
try {
JSONObject jsonObject = new JSONObject(json);
code = jsonObject.optString("code");
// message = jsonObject.optString("message");
} catch (JSONException e) {
e.printStackTrace();
}
return code;
}

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
flag = 0;

switch (checkedId) {
case R.id.teacherL:
flag = 1;
break;
case R.id.studentL:
flag = 2;
break;
}
}
}

OK,我们继续往后看看其他代码吧~
代码有点枯燥,我们看看效果图吧~




一、Adapter包(ScoreAdapter类)

package com.example.management;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

public class ItemDecoration extends RecyclerView.ItemDecoration {
private int space;

public ItemDecoration(int space) {
this.space = space;
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
// Add top margin only for the no first item to avoid double space between items
if (parent.getChildPosition(view) != 0) {
outRect.left = 0;
outRect.right = 0;
outRect.bottom = space;
outRect.top = 0;
}
}

}

二、Dom包
(1)Person类)
package com.example.management.Dom;

import java.util.List;

public class Person {

/**
* code : 0
* data : [["1","123","1","计算机","zhao"],["2","123",null,null,null],["3","123",null,null,null],["4","123",null,null,null],["12","123",null,null,null]]
* message : 获取所有学生信息成功!
*/

private int code;
private String message;
private List<List<String>> data;

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public List<List<String>> getData() {
return data;
}

public void setData(List<List<String>> data) {
this.data = data;
}

@Override
public String toString() {
return "Person{" +
"code=" + code +
", message='" + message + '\'' +
", data=" + data +
'}';
}
}

(2)Rabbit类(当时有点匆忙,没有改名字了,这也是关于人的一个类
package com.example.management.Dom;

public class Rabbit {
/**
* code : 0
* data : {"cscore":0,"smajor":"计算机","sno":"1"}
* message : 该账号存在,返回值!
*/

private int code;
private DataBean data;
private String message;

public Rabbit() {
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public DataBean getData() {
return data;
}

public void setData(DataBean data) {
this.data = data;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public static class DataBean {
/**
* cscore : 0
* smajor : 计算机
* sno : 1
*/

private int cscore;
private String smajor;
private String sno;

public int getCscore() {
return cscore;
}

public void setCscore(int cscore) {
this.cscore = cscore;
}

public String getSmajor() {
return smajor;
}

public void setSmajor(String smajor) {
this.smajor = smajor;
}

public String getSno() {
return sno;
}

public void setSno(String sno) {
this.sno = sno;
}
}
}

(3)Student类
package com.example.management.Dom;

public class Student {

private String Sno;
private String Cname;
private String Sname;
private String Sscore;
private String Smajor;
private String Cno;
public Student(){

}

public Student(String sno, String cname, String sname, String sscore, String smajor, String cno) {
Sno = sno;
Cname = cname;
Sname = sname;
Sscore = sscore;
Smajor = smajor;
Cno = cno;
}

public String getCno() {
return Cno;
}

public void setCno(String cno) {
Cno = cno;
}

public String getSno() {
return Sno;
}

public void setSno(String sno) {
Sno = sno;
}

public String getCname() {
return Cname;
}

public void setCname(String cname) {
Cname = cname;
}

public String getSscore() {
return Sscore;
}

public void setSscore(String sscore) {
Sscore = sscore;
}

public String getSname() {
return Sname;
}

public void setSname(String sname) {
Sname = sname;
}

public String getSmajor() {
return Smajor;
}

public void setSmajor(String smajor) {
Smajor = smajor;
}

@Override
public String toString() {
return "Student{" +
"Sno='" + Sno + '\'' +
", Cname='" + Cname + '\'' +
", Sname='" + Sname + '\'' +
", Sscore='" + Sscore + '\'' +
", Smajor='" + Smajor + '\'' +
", Cno='" + Cno + '\'' +
'}';
}
}

(4)StudentBean类
package com.example.management.Dom;

public class StudentBean {
private String Sno;
private String Spassword;
private String Sname;
private String Cno;
private String Cscore;
private String Smajor;

public StudentBean() {

}

public StudentBean(String sno,String smajor) {
this.Sno = sno;
this.Smajor = smajor;
}

public StudentBean(String sno,String Spassword,String Cno,String Smajor,String Sname) {
this.Sno = sno;
this.Spassword = Spassword;
this.Cno = Cno;
this.Smajor = Smajor;
this.Sname = Sname;
}

public StudentBean(String sno, String spassword, String sname, String cno, String cscore, String smajor) {
Sno = sno;
Spassword = spassword;
Sname = sname;
Cno = cno;
Cscore = cscore;
Smajor = smajor;
}

public String getSno() {
return Sno;
}

public void setSno(String sno) {
this.Sno = sno;
}

public String getSpassword() {
return Spassword;
}

public void setSpassword(String spassword) {
Spassword = spassword;
}

public String getSname() {
return Sname;
}

public void setSname(String sname) {
Sname = sname;
}

public String getCno() {
return Cno;
}

public void setCno(String cno) {
Cno = cno;
}

public String getCscore() {
return Cscore;
}

public void setCscore(String cscore) {
Cscore = cscore;
}

public String getSmajor() {
return Smajor;
}

public void setSmajor(String smajor) {
Smajor = smajor;
}
}

三、TeacherFrgment包
(1)TeacherHomeFragment类
package com.example.management.TeacherFrgment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.management.R;

public class TeacherHomeFragment extends Fragment {

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.teacher_home_fragment,container,false);
return view;
}
}

(2)TeacherMessageFragemnt类
package com.example.management.TeacherFrgment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.example.management.R;

public class TeacherMessageFragemnt extends Fragment {

private ListView listView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.teacher_message_fragment,container,false);
return view;
}
}

(3)TeacherScoreFragment类
package com.example.management.TeacherFrgment;

import com.example.management.AddorModifyActivity;
import com.example.management.ItemDecoration;
import com.example.management.OnRecyclerViewClickListener;
import com.example.management.R;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;

import com.alibaba.fastjson.JSON;
import com.example.management.Adapter.ScoreAdapter;
import com.example.management.Dom.Person;
import com.example.management.Dom.Student;
import com.example.management.Dom.StudentBean;
import com.example.management.R;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static android.content.ContentValues.TAG;
public class TeacherScoreFragment extends Fragment implements View.OnClickListener {

private String code;//服务器返回的值
private String data1;
private EditText textscore;
private DividerItemDecoration divider;
private ImageButton Ib_addStudentScore;

private Button btn_get;
private RecyclerView recyclerView;
private  LinearLayoutManager layoutManager;
private Person mData = null;
List<List<String>> dataMessage = null;
private LinkedList<Student> mmdata = null;//展示所有学生成绩
private ScoreAdapter mAdapter = null;
private Context mContext;
private Person person;
private Toolbar toolbar_teacher_score;

private String get_Sno;
private String get_Sscore;
private String get_Sname;
private String get_Smajor;
private String get_Cname;
private String get_Cno;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.teacher_score_fragment,container,false);
recyclerView = view.findViewById(R.id.recycleview);

//        recyclerView.setPadding(20, 0, 20, 0);
//        recyclerView.addItemDecoration(new ItemDecoration(-10));

toolbar_teacher_score = view.findViewById(R.id.toolbar_teacher_score);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar_teacher_score);
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);//去除toolbar的title
Ib_addStudentScore = view.findViewById(R.id.Ib_addStudentScore);

layoutManager = new LinearLayoutManager(this.getActivity(),LinearLayoutManager.VERTICAL,false);
//textscore = view.findViewById(R.id.textscore);
mContext = view.getContext();
sendRequestWithOkHttp();

return view;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Ib_addStudentScore.setOnClickListener(this);
}

private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
//Log.d(TAG, "handleMessage: 33333333333333333333333333");
//Log.d("123456", "handleMessage: "+msg.obj.toString());
code = jsonToJsonObject(msg.obj.toString());
if (code.equals("0")) {
//finish();
} else if(code.equals("-1")){//若账号不存在,跳转至注册页面
textscore.setText("");
Log.d(TAG, "handleMessage: 账号不存在");
}
return true;
}
});

private void sendRequestWithOkHttp() {
new Thread(new Runnable() {
@Override
public void run() {
try {
requestNet( "http://10.161.66.7:8080/three/servlet/SearchScoreServlet?");
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

/***
*网络请求
*@return void
*/
private void requestNet(String s) throws IOException {

OkHttpClient client = new OkHttpClient();
RequestBody responseBody = null;
responseBody = new FormBody.Builder().add("no", "all").build();
Request request = new Request.Builder().url(s).post(responseBody).build();
Call call = client.newCall(request);
Response response = call.execute();
Message message = handler.obtainMessage();
message.obj = response.body().string();
handler.sendMessage(message);
}

public String jsonToJsonObject(String json) {
String code =" ";
try {
JSONObject jsonObject = new JSONObject(json);
code = jsonObject.optString("code");
person =  JSON.parseObject(json,Person.class);
dataMessage = person.getData();
mmdata = new LinkedList<Student>();
for(List<String> attribute1 : dataMessage) {
String Sno = attribute1.get(0);
String Sscore =attribute1.get(4);
String Cname = attribute1.get(5);
String Smajor = attribute1.get(1);
String Sname= attribute1.get(2);
String Cno = attribute1.get(3);
Student stu = new Student(Sno,Cname,Sname,Sscore,Smajor,Cno);
Log.d(TAG, "jsonToJsonObject: stu "+stu);
mmdata.add(stu);
//加入分割线 161 163  164
divider = new DividerItemDecoration(this.getActivity(),DividerItemDecoration.VERTICAL);
mAdapter = new ScoreAdapter(mmdata,mContext);
divider.setDrawable(ContextCompat.getDrawable(this.getActivity(),R.drawable.divider));
recyclerView.addItemDecoration(divider);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(mAdapter);

//recycleview点击item事件
mAdapter.setItemClickListener(new OnRecyclerViewClickListener() {
@Override
public void onItemClickListener(View view) {
int position = recyclerView.getChildAdapterPosition(view);
List<String> myStudent = new ArrayList<>();
myStudent = dataMessage.get(position);
Log.d(TAG, "onItemClickListener: mystudent"+myStudent.toString());
//Student student = new Student();
get_Sno = myStudent.get(0);
get_Sscore = myStudent.get(3);
get_Smajor = myStudent.get(1);
get_Sname = myStudent.get(2);
get_Cname = myStudent.get(4);
get_Cno = myStudent.get(5);
Bundle bundle = new Bundle();
bundle.putString("get_Sno",get_Sno);
bundle.putString("get_Sscore",get_Sscore);
bundle.putString("get_Smajor",get_Smajor);
bundle.putString("get_Sname",get_Sname);
bundle.putString("get_Cname",get_Cname);
bundle.putString("get_Cno",get_Cno);
Intent intent = new Intent(mContext,AddorModifyActivity.class);
intent.putExtra("Message",bundle);
startActivity(intent);
}
@Override
public void onItemLongClickListener(View view) {

}
});
}

} catch (JSONException e) {
e.printStackTrace();
}
return code;
}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.Ib_addStudentScore:
Intent intent = new Intent(getActivity(), AddorModifyActivity.class);
startActivity(intent);
break;
default:break;
}
}

}

四、Utils包
StatusbarUtil类

package com.example.management.Utils;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class StatusbarUtil {
public static void setTransparentWindow(Activity activity, boolean flag) {
/**
* initialize items
*/
/**
* 通过设置全屏,设置状态栏透明
*
* @param activity
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色
Window window = activity.getWindow();
View decorView = window.getDecorView();
//两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
//导航栏颜色也可以正常设置
//window.setNavigationBarColor(Color.TRANSPARENT);
//light mode or dark mode
if (flag) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
} else {
Window window = activity.getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
attributes.flags |= flagTranslucentStatus;
//                attributes.flags |= flagTranslucentNavigation;
window.setAttributes(attributes);
}
}
}
}

五、增查改代码(删除功能有待完善,不展示了)
(1)AddorModifyActivity
package com.example.management;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import android.widget.ImageButton;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class AddorModifyActivity extends AppCompatActivity implements View.OnClickListener {

private EditText edit_Sno;
private EditText edit_Cname;
private EditText edit_Smajor;
private EditText edit_Sname;
private EditText edit_Score;
private EditText edit_Cno;

private String Sno;
private String Cname;
private String Smajor;
private String Sname;
private String code;
private String Score;
private String Cno;
private int AddStudent;
private int ModifyStudent;

private String set_Sno;
private String set_Cname;
private String set_Smajor;
private String set_Sname;
private String set_Score;
private String set_Cno;

private FloatingActionButton fab_saveStudentScore;
private FloatingActionButton fab_modifyStudentScore;
private Toolbar toolbar_add_modify;
private ImageButton Ib_backtoscore;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addor_modify);
edit_Sno = findViewById(R.id.edit_Sno);
edit_Cname = findViewById(R.id.edit_Cname);
edit_Smajor = findViewById(R.id.edit_Smajor);
edit_Sname = findViewById(R.id.edit_Sname);
edit_Score = findViewById(R.id.edit_Score);
edit_Cno = findViewById(R.id.edit_Cno);
fab_modifyStudentScore = findViewById(R.id.fab_modifyStudentScore);
fab_saveStudentScore = findViewById(R.id.fab_saveStudentScore);
toolbar_add_modify = findViewById(R.id.toolbar_add_modify);
Ib_backtoscore = findViewById(R.id.Ib_backtoscore);

fab_modifyStudentScore.setOnClickListener(this);
fab_saveStudentScore.setOnClickListener(this);
setSupportActionBar(toolbar_add_modify);
Ib_backtoscore.setOnClickListener(this);

getSupportActionBar().setDisplayShowTitleEnabled(false);//去除toolbar的title

if(getIntent()!=null){
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("Message");
if(bundle!=null){
set_Cname = bundle.getString("get_Cname");
set_Sname = bundle.getString("get_Sname");
set_Smajor = bundle.getString("get_Smajor");
set_Sno = bundle.getString("get_Sno");
set_Score = bundle
8000
.getString("get_Sscore");
set_Cno = bundle.getString("get_Cno");

edit_Sno.setText(set_Sno);
edit_Cname.setText(set_Cname);
edit_Smajor.setText(set_Smajor);
edit_Sname.setText(set_Sname);
edit_Score.setText(set_Score);
edit_Cno.setText(set_Cno);
}

}

}

private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
code = jsonToJsonObject(msg.obj.toString());
Log.d("hander", "code: "+code);
if (code.equals("0")) {
if(AddStudent==1&&ModifyStudent==0){
Toast.makeText(AddorModifyActivity.this, "增加成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AddorModifyActivity.this,TeacherHomePageActivity.class);
startActivity(intent);
}else if(AddStudent==0&&ModifyStudent==1){
Toast.makeText(AddorModifyActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AddorModifyActivity.this,TeacherHomePageActivity.class);
startActivity(intent);
}

//finish();
} else if(code.equals("-1")){//若账号不存在,跳转至注册页面
Toast.makeText(AddorModifyActivity.this, "操作失败", Toast.LENGTH_SHORT).show();
edit_Sno.setText("");
edit_Cname.setText("");
edit_Smajor.setText("");
edit_Sname.setText("");
edit_Score.setText("");
edit_Cno.setText("");
Intent intent = new Intent(AddorModifyActivity.this, TeacherHomePageActivity.class);
startActivity(intent);
}
return true;
}
});

private void sendRequestWithOkHttp() {
new Thread(new Runnable() {
@Override
public void run() {
try {
if(ModifyStudent==1&&AddStudent==0){
requestNet("http://10.161.66.7:8080/three/servlet/ModifyStudentServlet?");
}else if(ModifyStudent==0&&AddStudent==1){
requestNet("http://10.161.66.7:8080/three/servlet/AddStudentScoreServlet?");
}

} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}

private void requestNet(String s) throws IOException {
Sno = edit_Sno.getText().toString();//getText()要放到监听里面
Cname = edit_Cname.getText().toString();
Smajor = edit_Smajor.getText().toString();
Sname = edit_Sname.getText().toString();
Score = edit_Score.getText().toString();
Cno = edit_Cno.getText().toString();

OkHttpClient client = new OkHttpClient();
RequestBody responseBody = null;
responseBody = new FormBody.Builder().add("Sno", Sno)
.add("Cname", Cname)
.add("Smajor", Smajor)
.add("Sname", Sname)
.add("Score",Score)
.add("Cno",Cno)
.build();
Request request = new Request.Builder().url(s).post(responseBody).build();
Call call = client.newCall(request);
Response response = call.execute();
Message message = handler.obtainMessage();
message.obj = response.body().string();
handler.sendMessage(message);
}

public String jsonToJsonObject(String json) {
Log.d("hello", "jsonToJsonObject: " + json);
String code = "";
String message = null;
try {
JSONObject jsonObject = new JSONObject(json);
code = jsonObject.optString("code");
// message = jsonObject.optString("message");
} catch (JSONException e) {
e.printStackTrace();
}
return code;
}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.fab_modifyStudentScore:
ModifyStudent = 1;
sendRequestWithOkHttp();
break;
case R.id.fab_saveStudentScore:
AddStudent = 1;
Log.d("onclick", "onClick: 你点击了增加");
sendRequestWithOkHttp();
break;
case R.id.Ib_backtoscore:
Intent intent = new Intent(AddorModifyActivity.this,TeacherHomePageActivity.class);
startActivity(intent);
}
}

}

(2)ItemDecoration
package com.example.management;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

public class ItemDecoration extends RecyclerView.ItemDecoration {
private int space;

public ItemDecoration(int space) {
this.space = space;
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
// Add top margin only for the no first item to avoid double space between items
if (parent.getChildPosition(view) != 0) {
outRect.left = 0;
outRect.right = 0;
outRect.bottom = space;
outRect.top = 0;
}
}

}

(3)TeacherHomePageActivity
package com.example.management;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.example.management.TeacherFrgment.TeacherHomeFragment;
import com.example.management.TeacherFrgment.TeacherMessageFragemnt;
import com.example.management.TeacherFrgment.TeacherScoreFragment;

import java.util.ArrayList;
import java.util.List;

public class TeacherHomePageActivity extends AppCompatActivity {

private BottomNavigationView bottomNavigationView;
private int lastIndex;
List<Fragment> fragments;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teacher_home_page);
initBottomNavigation();
initData();
setFragmentPosition(0);
}

private void initData() {
fragments = new ArrayList<>();
fragments.add(new TeacherScoreFragment());
fragments.add(new TeacherMessageFragemnt());
fragments.add(new TeacherHomeFragment());
setFragmentPosition(1);
}

private void setFragmentPosition(int i) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment currentFragment = fragments.get(i);
Fragment lastFragment = fragments.get(lastIndex);
lastIndex= i;
ft.hide(lastFragment);
if(!currentFragment.isAdded()){
getSupportFragmentManager().beginTransaction().remove(currentFragment).commit();
ft.add(R.id.tt_frameLayout,currentFragment);
}
ft.show(currentFragment);
ft.commitAllowingStateLoss();
}

public void initBottomNavigation() {
bottomNavigationView = findViewById(R.id.bv_teacher_bottomNavigation);
// 解决当item大于三个时,非平均布局问题
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.rb_scoreT:
setFragmentPosition(0);
break;
case  R.id.rb_messageT:
setFragmentPosition(1);
break;
case R.id.rb_homeT:
setFragmentPosition(2);
break;
default:
break;
}
// 这里注意返回true,否则点击失效
return true;
}
});
}
}

(4)MainActivity
package com.example.management;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

private static final long DELAY = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final Intent localIntent = new Intent(MainActivity.this, LoginActivity.class);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
startActivity(localIntent);
}
};
timer.schedule(task,DELAY);
}
}

(5)OnRecyclerViewClickListener
package com.example.management;

import android.view.View;

import com.example.management.Dom.Student;

public interface OnRecyclerViewClickListener {
void onItemClickListener(View view);
void onItemLongClickListener(View view);
}

后台代码(展示部分)

(1)AddStudentScoreServlet类
package servlet;

import DAO.StudentDao;
import Dom.BaseBean;
import Dom.StudentBean;
import com.alibaba.fastjson.JSON;
import jdbc.DBUtilsTemplate;
import jdbc.DButils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "AddStudentScoreServlet")
public class AddStudentScoreServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
request.setCharacterEncoding("utf8");//添加,不然会中文乱码
String Sno = request.getParameter("Sno");
String Sname = request.getParameter("Sname");
String Cname = request.getParameter("Cname");
String Smajor = request.getParameter("Smajor");
String Score = request.getParameter("Score");
String Cno = request.getParameter("Cno");
response.setContentType("text/html;charset=utf-8");
int flag = 0;
int flag2 = 0;
String Spassword=null;
String json = null;

//连接数据库
DButils dButils = new DButils();
dButils.getConnection();
BaseBean data = new BaseBean();
StudentBean studentBean = new StudentBean();

if(Sno==null||Sno.equals("")){
data.setCode(-1);
data.setData(studentBean);
data.setMessage("该账号存在,插入失败");
}else{
int flag1 = dButils.isStudentExecstByTeacher(Sno);
if(flag1 == 1){
System.out.println("失败");
data.setCode(-1);
data.setData(studentBean);
data.setMessage("该账号存在,插入失败");
}else{
try{
StudentDao studentDao = new StudentDao();
flag = studentDao.saveStudentScore(Sno,"123",Cno,Smajor,Sname);
flag2 = studentDao.ModifyStudentScore2(Cno,Sno,Score,Cname);
if(flag ==1&&flag2==1){
data.setCode(0);
data.setData(studentBean);
data.setMessage("增加成功");
}else{
data.setCode(-2);
data.setData(studentBean);
data.setMessage("系统繁忙,稍后重试");
}
}catch (SQLException e){
e.printStackTrace();
}
}

json = JSON.toJSONString(data);
System.out.println(json);
}

try{
response.getWriter().println(json);
}catch (Exception e){
e.printStackTrace();
}finally {
response.getWriter().close();
}
dButils.disConnection();
}
}

(2)ModifyStudentServlet类
package servlet;

import DAO.StudentDao;
import Dom.BaseBean;
import Dom.StudentBean;
import com.alibaba.fastjson.JSON;
import jdbc.DButils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "ModifyStudentServlet")
public class ModifyStudentServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");//添加,不然会中文乱码
String Sno = request.getParameter("Sno");
String Sname = request.getParameter("Sname");
String Smajor = request.getParameter("Smajor");
String Cname = request.getParameter("Cname");
String Score = request.getParameter("Score");
String Cno = request.getParameter("Cno");
int flag2 = 0;
int flag = 0;
response.setContentType("text/html;charset=utf-8");
String Spassword=null;

//连接数据库
DButils dButils = new DButils();
dButils.getConnection();
BaseBean data = new BaseBean();
StudentBean studentBean = new StudentBean();
int flag1 = dButils.isStudentExecstByTeacher(Sno);//判断学号是否存在
System.out.println(flag1+"   =====flag1");
if(flag1 == 1){
try{
StudentDao studentDao = new StudentDao();
flag = studentDao.ModifyStudentScore(Sno,Spassword,Cno,Smajor,Sname);
flag2 = studentDao.saveStudentScore2(Cno,Sno,Score,Cname);
System.out.println("flga  ===="+flag);
if(flag ==1){
System.out.println("修改成功");
data.setCode(0);
data.setData(studentBean);
data.setMessage("修改成功");
}else{
System.out.println("修改失败");
data.setCode(-2);
data.setData(studentBean);
data.setMessage("系统繁忙,稍后重试");
}
}catch (SQLException e){
e.printStackTrace();
}
}else{
data.setCode(-1);
data.setData(studentBean);
data.setMessage("该账号不存在,修改失败");
}

String json = JSON.toJSONString(data);
System.out.println(json);
try{
response.getWriter().println(json);
}catch (Exception e){
e.printStackTrace();
}finally {
response.getWriter().close();
}
dButils.disConnection();
}
}

(3)RegisterTeacherServlet类
package servlet;

import Dom.BaseBean;
import Dom.TeacherBean;
import com.alibaba.fastjson.JSON;
import jdbc.DButils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RegisterTeacherServlet")
public class RegisterTeacherServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");//添加,不然会中文乱码
String Tno = request.getParameter("no");
String Tpassword = request.getParameter("password");
System.out.println("教师号: "+Tno);
System.out.println("教师密码: "+Tpassword);
response.setContentType("text/html;charset=utf-8");
if(Tno.length()>10||Tno==null||Tpassword==null||Tpassword.equals("")){
System.out.println("用户名长度不对或者密码为空");
return;
}

DButils dButils = new DButils();
dButils.getConnection();
BaseBean data = new BaseBean();
TeacherBean teacherBean = new TeacherBean();

if(dButils.isTeacherExecstInDB(Tno,Tpassword)==1){//用户账号存在(失败)
data.setCode(-1);
data.setData(teacherBean);
data.setMessage("账号存在,请先重新注册!");
//System.out.println("账号账号存在,请先重新注册");
}else if(dButils.isTeacherExecstInDB(Tno,Tpassword)==0){
boolean flag = dButils.insertTeacherDB(Tno,Tpassword);
if(!flag){
data.setCode(0);
data.setData(teacherBean);
data.setMessage("注册成功!");
}else{
data.setCode(-2);
data.setData(teacherBean);
data.setMessage("系统繁忙,稍后重试!");
}

}
String json = JSON.toJSONString(data);
try{
response.getWriter().println(json);
}catch (Exception e){
e.printStackTrace();
}finally {
response.getWriter().close();
}
dButils.disConnection();
}
}

(4)SearchScoreServlet类
package servlet;

import DAO.StudentDao;
import Dom.BaseBean;
import Dom.StudentBean;
import com.alibaba.fastjson.JSON;
import javafx.beans.binding.ObjectExpression;
import jdbc.DButils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.ValidationException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Vector;

@WebServlet(name = "SearchScoreServlet")
public class SearchScoreServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request,response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf8");//添加,不然会中文乱码
String Sno = request.getParameter("no");

response.setContentType("text/html;charset=utf-8");

System.out.println(Sno);
//连接数据库

DButils dButils = new DButils();
dButils.getConnection();
BaseBean data = new BaseBean();
StudentDao studentDao = new StudentDao();

Vector<Vector<StudentBean>> studentBean= new Vector<>();

if(Sno.equals("all")){
try {
studentBean = studentDao.queryStudentBean("select DISTINCT s.sno,s.smajor,s.sname,c.cno,c.cscore,c.cname \n" +
"from student as s LEFT join course as c \n" +
"on s.sno=c.sno and s.cno=c.cno\n ",new Object[]{"Sno","Smajor","Sname","Cscore","Cname","Cno"});
System.out.println(studentBean);
if(studentBean!=null){
data.setCode(0);
data.setData(studentBean);
data.setMessage("获取所有学生信息成功!");
}else{
data.setCode(0);
data.setData(studentBean);
data.setMessage("获取所有学生信息失败!");
}
} catch (SQLException e) {
e.printStackTrace();
}
}else{
System.out.println("单个查询"+Sno);
try {
studentBean = studentDao.searchStudentBean("select DISTINCT s.sno,s.smajor,s.sname,c.cno,c.cscore,c.cname \n" +
"from student as s LEFT join course as c \n" +
"on s.sno=c.sno and s.cno=c.cno\n",new Object[]{"Sno","Smajor","Sname","Cscore","Cname","Cno"},Sno);
System.out.println(studentBean);
if(studentBean!=null){
data.setCode(0);
data.setData(studentBean);
data.setMessage("获取学生信息成功!");
}else{
data.setCode(0);
data.setData(studentBean);
data.setMessage("获取学生信息失败!");
}
} catch (SQLException e) {
e.printStackTrace();
}

}
System.out.println("打印studentBean: "+studentBean);
String json = JSON.toJSONString(data);
System.out.println(json);
try{
response.getWriter().println(json);
}catch (Exception e){
e.printStackTrace();
}finally {
response.getWriter().close();
}
dButils.disConnection();
}
}

小白,有好多地方可以改进,请多多指教~
想要完整代码和,可以私我~

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: