开发测试平台(三)登陆页面和平台首页

一、在mapper包里的UserMapper这个接口里新增一个checkUser,html

二、在userMapper.xml文件中写入查询的sql语句 where 后面1=1 是为了不 有and 报错,if里的test标签是固定写法前端

三、接下来写service层,在UserService类里新增一个checkUser方法,git

把user1 属性复制给loginUsersql

bBeanUtils.copyProperties(user1,loginUser);

四、在vo包内新建一个LoginUser类,只有一个属性userName,这个用来登陆后带入用户的后端

五、在LoginController 里新增一个方法 login  ,用于登陆,注意入参使用model map ,添加loginUser 到session中session

六、添加拦截器,同时排除掉、/login/loginPage   login/login,/login/registerPage,/login/regiterapp

七、修改前端的登陆页面代码,input输入框中 添加 name=“userName”,name=“password”,不然数值传不到后端,action 路径写上controller 的路径,而且添加错误信息返回给页面spa

<input type="text" name="userName" class="form-control" placeholder="用户名"
       value="<#if user??>${user.userName!}</#if>">
<input type="password" name="password" class="form-control" placeholder="密码"
       value="<#if user??>${user.password!}</#if>">
<div class="form-group">
    <span style="color:red">${msg!}</span>
</div>

八、登陆后,重定向到index页面,日志

modelAndView.setViewName("redirect:/index");

在layout中导航栏中添加code

<span><#if Session.loginUser??>
                ${Session.loginUser.userName!}欢迎您!
                </#if>
</span>

在layout 页面中,添加

<#macro body>
</#macro>

在index.ftl中使用

<#include "/layout/layout.ftl">
<@body>
你好
</@body>

九、加入日志,添加lombok pom文件,使用日志输出

log.info("{}登陆成功",loginUser.getUserName());