微笑的萌新
2020-12-04 16:10
采纳率: 100%
浏览 702
已采纳

SSM框架登录后把用户名存入session中

//管理员登录功能的请求(controller层)

@RequestMapping("/loginForadministrator")
public ModelAndView loginForadministrator(Administrator administrator, HttpSession session) {
    boolean flag = administrator_service.loginForadministrator(administrator);
    session.setAttribute("user1",);//用session取得登陆时输入的username值
    ModelAndView mv = new ModelAndView();
    if (flag) {
        mv.setViewName("admin_ad");
    } else {
        mv.setViewName("error");
    }
   return mv;

}

//jsp页面显示session

<%--登陆后显示管理员姓名--%>
        <b class="text-black">欢迎您</b>
        &nbsp;&nbsp;
      <a class="text-black">
          <%=session.getAttribute("user1")%>

      </a>

        </span></a>
//管理员登录功能(ServiceImpl.java)
public boolean loginForadministrator(Administrator administrator) {
    Administrator administrator1 = administrator_Mapper.loginForadministrator(administrator);
    if (administrator1 != null) {
        return true;
    } else {
        return false;
    }
}

//Mapper接口

Administrator loginForadministrator(Administrator administrator);

//Service接口

boolean loginForadministrator(Administrator administrator);

//xml文件

<!--登录功能之管理员登录-->
<select id="loginForadministrator" resultType="Administrator">
select * from school_hdu01.administrator
where username = #{username} and password = #{password}

希望帮解决下,这样的情况怎么把登录界面输入的username值保存在sessionz

2条回答 默认 最新

相关推荐 更多相似问题