7月9日 SSM 周一

package com.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dto.Emp;
import com.util.PageUtils;

public class EmpDao extends HibernateDaoSupport{

    public int login(String id, String mm) {

        String sql = " select * from t_login where id = '"+id+"' and mm = '"+mm+"' ";
        SQLQuery query = getSession().createSQLQuery(sql);
        System.out.println(query.getQueryString());
        Object object = query.uniqueResult();

        System.out.println(object);

        if(object!=null){
            return 1;
        }else{
            return 0;
        }
    }

    public List findEmpList(PageUtils pu) {
        // TODO Auto-generated method stub
        System.out.println("findEmpList");
        Query query = getSession().createQuery("from Emp").setFirstResult(pu.getStartIndex()).setMaxResults(pu.getPageSize());//查询
        List list = query.list();
        List find = getHibernateTemplate().find("from Emp");
        System.out.println("find结果"+find);
        System.out.println("list结果"+list);


        return list;
    }

    public Integer getCount() {
        // TODO Auto-generated method stub
        Query query = getSession().createQuery("select count(*) from Emp");
        Object result = query.uniqueResult();
        Integer count = Integer.valueOf(result.toString());
        return count;
    }

}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'login.jsp' starting pagetitle>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    

  <script type="text/javascript" src="js/jquery-1.8.2.js">script>
  <script type="text/javascript">
    function login(){
        var id = $("[name='id']").val();
        var mm = $("[name='mm']").val();
        if(id==""|mm==""){
            alert("用户名或密码不能为空");
        }else{
            $.post(
                "e_login",
                {id:id,mm:mm},
                function (num){
                    if(num==1){
                        alert("登录成功");
                        location = "e_list";
                    }else{
                        alert("登录失败");
                    }
                },"json"
            );
        }
    }
  script>

  head>

  <body>
    id<input type="text" name="id"><br>
    mm<input type="password" name="mm"><br>
    <input type="button" value="登录" onclick="login()">
  body>
html>
package com.dto;

import java.util.Set;

public class Emp {
    private Integer id;
    private String name;
    private String age;
    private Dept dept;
    private Leader leader;
    public Emp() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Emp(Integer id, String name, String age, Dept dept, Leader leader) {
        super();
        this.id = id;
        this.name = name;
        this.age = age;
        this.dept = dept;
        this.leader = leader;
    }
    @Override
    public String toString() {
        return "Emp [id=" + id + ", name=" + name + ", age=" + age + ", dept="
                + dept + ", leader=" + leader + "]";
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAge() {
        return age;
    }
    public void setAge(String age) {
        this.age = age;
    }
    public Dept getDept() {
        return dept;
    }
    public void setDept(Dept dept) {
        this.dept = dept;
    }
    public Leader getLeader() {
        return leader;
    }
    public void setLeader(Leader leader) {
        this.leader = leader;
    }


}

所谓的生存,就是吞噬他人。
《东京食尸鬼》

你可能感兴趣的:(2018)