使用spring+ibatis+jquerymobile做的一个简单的用户登录

sql代码:<select id="getVaildateUser" resultClass="AppUser" parameterClass="AppUser">
       SELECT
        * from omcm_user
      WHERE UserName=#username#
      <dynamic>
       <isNotEmpty property="password">AND Password =#password# </isNotEmpty>    
      </dynamic>
    </select>

dao层:public boolean loginform(AppUser user);

daoImpl层:

public boolean loginform(AppUser user) {
  try {
   AppUser users = (AppUser) getSqlMapClientTemplate().queryForObject("getVaildateUser",user);
   return users==null?false:true;
  } catch (DataAccessException e) {
   e.printStackTrace();
  }return false;
 }

server层: public boolean loginform(AppUser user);

serverImpl层:

public boolean loginform(AppUser user) {
  return systemDao.loginform(user);
 }

control层:

public void loginIndex(HttpServletRequest request,
   HttpServletResponse response, AppUser user) {
  Map<String, Boolean> map=new HashMap<String, Boolean>();
  boolean resu=systemService.loginform(user);
  map.put("msg", resu);
  Util.writeUtf8Text(response, JsonUtil.objectjson(map));
 }

页面代码:

<script type="text/javascript">
 $(document).ready(function() { 
        $("input[id]").bind("focus",function () {  
         if($(this).attr("id")=='username'||$(this).attr("id")=='password') 
          $(this).attr("value","");  
          });  
          $("#submit").bind("click", function() { 
               if (valid()) {
                $.ajax({ 
                 type: "POST", 
                  url: "http://localhost:8080/OmcmWap/system.do?event=loginIndex", 
                  data: $("#loginform").serialize(),
                  success : function(data) {
          if (data=='{"msg":true}') {
           alert("登录成功!");
            $.mobile.changePage("content/first.html","slidedown", true, true);
          } else {
           alert("登录失败!");
              $.mobile.changePage("content/loginfail.html","slidedown", true, true); 
          }
         },
         error : function(data) {
          alert("出错了,请联系管理员!");
         }
                  });  
                } 
             }) 
          }); 
         function valid(){ 
            if($("#username").attr("value")==''||$("#password").attr("value")=='') 
            { 
                $.mobile.changePage("content/loginfail.html","slidedown", true, true); 
                return false;            
            } 
            return true; 
       }; 
</script>
<style type="text/css">
 p {
  font-size: 1.5em;
  font-weight: bold;
 }
 #submit{
  float:right; margin:10px;
 }
 #toregister{
  float:right; margin:10px;
 }
 #toregist{
  float:left; margin:10px;
 }
 </style>

</head>
<body>
<section id="page1" data-role="page">
  <header data-role="header" data-theme="b">
  <h1>用户登录</h1>
  </header>
  <div data-role="content" class="content">
  <form method="post" id="loginform">
  <input type="text" id="username" name="username" value="用户名"/><br>
  <input type="password" name="password" id="password" value="密码输入提示"/>
  <a href="#" data-role="button" id="toregister">注册</a>
  <a href="#" data-role="button" id="submit" data-theme="b">登录</a>
  </form>
  </div>
  <footer data-role="footer"><h1>
  版权所有中国移动
  </h1></footer>
</section>
</body>

原文地址:https://www.cnblogs.com/bingrong/p/3169682.html