新零售支付全家桶


完成登陆功能

改造后端登陆方法

修改UserCOntroller.java中的代码

@PostMapping("login")
@ApiOperation("登录")
public R login(@RequestBody LoginForm form){
    //表单校验
    ValidatorUtils.validateEntity(form);

    //用户登录
    long userId = userService.login(form);

    //生成token
    String token = jwtUtils.generateToken(userId);

    Map<String, Object> map = new HashMap<>();
    map.put("token", token);
    map.put("expire", jwtUtils.getExpire());

    return R.ok(map);
}

绑定登陆页面

创建LoginActivity.java,并且绑定login.html页面

public class LoginActivity extends AppCompatActivity {
    private WebView login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        login=findViewById(R.id.login);
        WebSettings settings=login.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setDomStorageEnabled(true);
        login.addJavascriptInterface(new LoginScript(),"login");
        login.loadUrl("file:///android_asset/login.html");
    }

    public class LoginScript{
        @JavascriptInterface
        public void toOrderPage(){
            Intent intent=new Intent();
            intent.setClass(LoginActivity.this,OrderActivity.class);
            startActivity(intent);
            finish();

        }
    }
}

页面列表

ITEM_HTML