学了dw 就可以做网站了吗,有什么网站可以做投票,crm管理系统登录,wordpress h5幻灯片1.Model层——User类的设计
同上一篇文章用户添加。
2. dao层——UserDao的设计
在UserDao中添加登陆方法的代码。
public boolean Login(User user){//根据用户信息执行查询操作#xff0c;查到返回true,没查到返回falseString strUserNameuser.getUsername();String str…1.Model层——User类的设计同上一篇文章用户添加。2. dao层——UserDao的设计在UserDao中添加登陆方法的代码。public boolean Login(User user){ //根据用户信息执行查询操作查到返回true,没查到返回false String strUserNameuser.getUsername(); String strPassworduser.getPassword(); Integer type user.getType(); Cursor cursordb.query(user_table,null,username? and password? and type?, new String[]{strUserName,strPassword,String.valueOf(type)},null,null,null ); if(cursor.moveToNext()){ return true; }else { return false; } }3. service层——UserService设计(1)接口UserService添加登陆方法声明。public boolean Login(User user);2实现类UserServiceImpl添加登陆方法的实现。public boolean Login(User user) { return userDao.Login(user); }4. View层——LoginActivity设计(1)布局文件activity_login.xml设计?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android xmlns:apphttp://schemas.android.com/apk/res-auto xmlns:toolshttp://schemas.android.com/tools android:layout_widthmatch_parent android:layout_heightmatch_parent android:orientationvertical android:padding12dp android:gravitycenter android:backgroundcolor/colorBlue tools:context.LoginActivity LinearLayout android:layout_widthmatch_parent android:layout_height450dp android:backgrounddrawable/login_box_background android:orientationvertical TextView android:idid/textView android:layout_widthmatch_parent android:layout_heightwrap_content android:textSize40sp android:layout_marginBottom20dp android:gravitycenter android:textWelcome / EditText android:idid/etUserName android:layout_widthmatch_parent android:layout_heightwrap_content android:ems10 android:inputTypetextPersonName android:hint用户名 android:textSizedimen/fontSize android:drawableLeftdrawable/username / EditText android:idid/etPassword android:layout_widthmatch_parent android:layout_heightwrap_content android:ems10 android:inputTypetextPassword android:hint密码 android:textSizedimen/fontSize android:drawableLeftdrawable/password android:maxLength10 / LinearLayout android:layout_widthmatch_parent android:layout_heightwrap_content android:orientationhorizontal RadioGroup android:layout_widthmatch_parent android:layout_heightwrap_content android:orientationhorizontal RadioButton android:idid/radStudent android:layout_width0dp android:layout_weight1 android:layout_heightwrap_content android:checkedtrue android:textSizedimen/fontSize android:text学生 / RadioButton android:idid/radTeacher android:layout_width0dp android:layout_weight1 android:layout_heightwrap_content android:textSizedimen/fontSize android:text教师 / /RadioGroup /LinearLayout Button android:idid/btLogin android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop20dp android:backgrounddrawable/new_btn_background android:textColorcolor/colorWhite android:layout_marginLeft20dp android:layout_marginRight20dp android:textSizedimen/fontSize android:textLogin / LinearLayout android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop20dp android:orientationhorizontal CheckBox android:idid/chkAutoLogin android:layout_width0dp android:layout_heightwrap_content android:layout_weight2 android:textSizedimen/fontSize android:text自动登陆 / CheckBox android:idid/chkSavePass android:layout_width0dp android:layout_heightwrap_content android:layout_weight3 android:checkedtrue android:text记住密码 android:textSizedimen/fontSize / /LinearLayout LinearLayout android:layout_widthmatch_parent android:layout_heightwrap_content android:layout_marginTop20dp android:orientationhorizontal TextView android:idid/tvReg android:layout_width0dp android:layout_heightwrap_content android:layout_weight3 android:textSizedimen/fontSize android:textColorcolor/colorBlue android:layout_marginLeft30dp android:text用户注册 android:textStylebold / TextView android:idid/tvForgetPass android:layout_width0dp android:layout_heightwrap_content android:layout_weight2 android:textSizedimen/fontSize android:textColorcolor/colorBlue android:layout_marginLeft50dp android:textStylebold android:text忘记密码 / /LinearLayout /LinearLayout /LinearLayout(2)主类LoginActivity设计package com.example.myactivitydemo; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; import com.example.myactivitydemo.entity.User; import com.example.myactivitydemo.service.UserService; import com.example.myactivitydemo.service.impl.UserServiceImpl; import com.example.myactivitydemo.util.DbHelper; import com.example.myactivitydemo.util.MD5Util; public class LoginActivity extends AppCompatActivity { private EditText etUserName; private EditText etPassword; private Button btLogin; private CheckBox chkSavePass; private CheckBox chkAutoLogin; private TextView tvReg; private RadioButton radStudent; private RadioButton radTeacher; //定义两个成员变量 private SharedPreferences sp; private SharedPreferences.Editor editor; private UserService userService; private int type; Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); initView(); //实例化 spgetSharedPreferences(user,0); editorsp.edit(); //读取用户信息 String strUserNamesp.getString(username,); String strPasswordsp.getString(password,); etUserName.setText(strUserName); etPassword.setText(strPassword); tvReg.setOnClickListener(new View.OnClickListener() { Override public void onClick(View v) { Intent intentnew Intent(LoginActivity.this,RegisterActivity.class); startActivity(intent); } }); btLogin.setOnClickListener(new View.OnClickListener() { Override public void onClick(View v) { String strUserNameetUserName.getText().toString().trim(); String strPasswordetPassword.getText().toString().trim(); if(radStudent.isChecked()){ type1; }else{ type2; } //身份验证 userServicenew UserServiceImpl(LoginActivity.this); User usernew User(); user.setUsername(strUserName); user.setPassword(strPassword); user.setType(type); if(userService.Login(user)){ if(chkSavePass.isChecked()){ //执行记住密码的操作 editor.putString(username,strUserName); editor.putString(password,etPassword.getText().toString()); editor.commit();//提交 } Intent intentnew Intent(LoginActivity.this,InfoActivity.class); startActivity(intent); }else{ Toast.makeText(LoginActivity.this, 用户名或密码错误,Toast.LENGTH_LONG).show(); } } }); } public void initView(){ etUserNamefindViewById(R.id.etUserName); etPasswordfindViewById(R.id.etPassword); btLoginfindViewById(R.id.btLogin); chkAutoLoginfindViewById(R.id.chkAutoLogin); chkSavePassfindViewById(R.id.chkSavePass); tvRegfindViewById(R.id.tvReg); radStudentfindViewById(R.id.radStudent); radTeacherfindViewById(R.id.radTeacher); } }最后是实现效果