学生端登陆
1.前端
代码如下:
package com.example.mypad.slice;
import com.alibaba.fastjson.JSON;
import com.example.mypad.ResourceTable;
import com.example.mypad.utils.HttpClient;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TextField;
import ohos.agp.window.dialog.ToastDialog;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
public class LoginAbilitySlice extends AbilitySlice {
private ListContainer list_course_ListContainer;
private Button user_icon;
@Override
public void onStart(Intent intent){
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_pad_login);
login_setting();
new Thread(() -> {
String test = HttpClient.findHistorysByC_id("102");
System.out.println("-----------------------------------------------------------------------------------------"+test);
}).start();
}
private void login_setting(){
Button btn_login = (Button) findComponentById(ResourceTable.Id_btn_login);
TextField account_field = (TextField) findComponentById(ResourceTable.Id_account);
TextField pwd_field = (TextField) findComponentById(ResourceTable.Id_pwd);
btn_login.setClickedListener(lis->{
String account = account_field.getText();
String pwd = pwd_field.getText();
if (account.equals("")||account.equals(null)||pwd.equals("")||pwd.equals(null)){
new ToastDialog(getContext()).setText("请输入完整").show();
return;
}
new Thread(() -> {
String res = HttpClient.stu_login(account,pwd);
getUITaskDispatcher().asyncDispatch(() -> {//获取UI 主线
new ToastDialog(getContext()).setText(res).show();
});
}).start();
});
}
}
public static String stu_login(String account,String pwd){
String url = "http://t40g792468.qicp.vip/stu_login_or_register/login?account="+account+"&pwd="+pwd;
return doGet(url);
}
2.后端
代码如下:
@Query(nativeQuery = true,value = "SELECT distinct account,pwd from student_account WHERE account=?1 AND pwd=?2") //原生SQL方法
public List<Object>login (String account,String pwd);
@RequestMapping("/login")
@ResponseBody
public String login (String account,String pwd){
if ( studentAccountDao.login(account, pwd)==null)
return "账户或密码错误";
return "登陆成功";
}