- 浏览: 17449 次
- 性别:
- 来自: 湖南
最新评论
1. denglu.jsp 中的
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户登陆</title>
<link href="<%=basePath %>style/main.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath%>style/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath %>js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery-ui.js"></script>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
<script type="text/javascript">
function login(){
var studentName1=document.getElementById("studentName").value;
var studentPassword1 = document.getElementById("studentPasswod").value;
if(studentName1==""){
document.getElementById("yonghus").innerHTML="<font color='red'>请输入用户名!</font>";
return ;
}
if(studentPassword1==""){
document.getElementById("mimas").innerHTML="<font color='red'>请输入密码!</font>";
return ;
}
$.ajax({
type: "post",
url: "<%=basePath%>background/student!findByNamePassword",
data: 'studentName='+studentName1+'&studentPassword='+studentPassword1,
success: function(msg){
if(msg=="true"){
document.getElementById("loginForm").submit();
}else{
document.getElementById("tishi").innerHTML="<font color='red'>用户名或者密码错误。请重新输入</font>";
}
}
});
}
function yichu(){
document.getElementById("yonghus").innerHTML="";
}
function yichu1(){
document.getElementById("mimas").innerHTML="";
}
//注册
function zhuce(){
$("#addStu").dialog({title: '注册学生信息'});
return false;
}
//验证 注册信息
function checkAddStu(){
if($("#zstudentName").val()==""){
$("#zname").html("<font color='red'>请输入用户!</font>");
return;
}
if($("#zstudentPassword").val()==""){
$("#ztpassword").html("<font color='red'>请输入密码!</font>");
return;
}
if($("#zstudentPassword1").val()==""){
$("#ztpassword1").html("<font color='red'>请再次输入密码!</font>");
return;
}
if($("#zstudentPassword").val()!=$("#zstudentPassword1").val()){
$("#ztpasswordx").html("<font color='red'>两次输入密码不一致!</font>");
return;
}
if($("#zsex").val()==""){
$("#ztsex").html("<font color='red'>请输入性别!</font>");
return;
}
if($("#zbanji").val()==""){
$("#ztbanji").html("<font color='red'>请输入班级!</font>");
return;
}
$.ajax({
type: "post",
url: "<%=basePath %>background/student!findByName",
data: 'studentName='+$("#zstudentName").val(),
success: function(msg){
if(msg==0){
$("#addStuForm").submit();
}else{
$("#zname").html("<font color='red'>该用户已经存在!</font>");
}
}
});
}
//失去焦点的时候去掉末尾提示信息
function losname(){
$("#zname").html("");
}
function lospassword(){
$("#ztpassword").html("");
}
function lospassword1(){
$("#ztpassword1").html("");
}
function losbanji(){
$("#ztbanji").html("");
}
function losname(){
$("#zname").html("");
}
function loaslianci(){
$("#ztpasswordx").html("");
}
</script>
</head>
<body>
<!-- 注册学生信息 -->
<div id="addStu" style="display:none">
<form action="<%=basePath%>background/student!saveAll" id="addStuForm" method="post" >
用 户 名:
<input type="text" name="zstudentName" id="zstudentName" onblur="javacript:losname();"/> <span id="zname"></span>
<br />
<br />
密 码:
<input type="password" name="zstudentPassword" id="zstudentPassword" onblur="javacript:lospassword();" onclick="javacript:loaslianci();"/> <span id="ztpassword"></span>
<br />
<br />
确认密码:
<input type="password" name="zstudentPassword1" id="zstudentPassword1" onblur="javacript:lospassword1();" onclick="javacript:loaslianci();"/> <span id="ztpassword1"></span>
<br />
<span id="ztpasswordx"></span>
<br />
性 别:
<input type="radio" name="zsex" id="zsex" value="男" checked="checked"/>男
<input type="radio" name="zsex" id="zsex" value="女" />女
<br />
<br />
班 级:
<input type="text" name="zbanji" id="zbanji" onblur="javacript:losbanji();"/> <span id="ztbanji"></span>
<br />
<br />
<div align="center">
<a href="javascript:checkAddStu();">
<img alt="" src="<%=basePath%>image/queren.gif" border="0" />
</a>
<a href="" onclick="javascript:go: back(-1);">
<img alt="" src="<%=basePath%>image/fanhui.gif" border="0" />
</a>
</div>
</form>
</div>
<!-- 结束注册学生信息 -->
<div align="center">
<form action="<%=basePath%>background/student!findAll" id="loginForm" method="post">
<table>
<tr><td><span id="tishi"></span></td>></tr>
<br />
<br />
<br />
<br />
<br />
<tr>
<td>用户姓名:<input type="text" id="studentName" name="studentName" onblur="javascript:yichu();"/><span id="yonghus"></span></td>
</tr>
<br />
<br />
<tr>
<td>用户密码:<input type="password" id="studentPasswod" name="studentPasswod" onblur="javascript:yichu1();"/><span id="mimas"></span> </td>
</tr>
<br />
<br />
<tr>
<td> <input type="button" value="确认" onclick="javascript: login();" /> <input type="button" value="注册" onclick="javascript: zhuce();" /> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
2.action 中的
package cn.com.kxrj.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
import cn.com.kxrj.manager.StudentManager;
import cn.com.kxrj.tool.Pagination;
public class StudentAction extends ActionSupport implements RequestAware,SessionAware{
/**
*
*/
private static final long serialVersionUID = 1L;
private StudentManager studentManager;
private Map<String,Object > request;
private Map<String,Object > session;
private PrintWriter out;
public String findAll(){
HttpServletRequest request= ServletActionContext.getRequest();
String currPage=request.getParameter("currPage");
if(currPage==null||currPage.equals("")){
currPage=String.valueOf("1");
}
Pagination pagination =studentManager.findAll(Integer.valueOf(currPage));
request.setAttribute("data", pagination.getList());
request.setAttribute("currPage", pagination.getCurrPage());
request.setAttribute("maxPage", pagination.getMaxPage());
request.setAttribute("maxRow", pagination.getMaxRow());
request.setAttribute("pageSize", pagination.getPageSize());
return "student_list";
}
public String deleteById(){
HttpServletRequest request = ServletActionContext.getRequest();
String studentId = request.getParameter("studentId");
System.out.println("学生ID "+studentId);
studentManager.deleteById(Integer.valueOf(studentId));
return this.findAll();
}
public String saveAll(){
HttpServletRequest request = ServletActionContext.getRequest();
String studentName =request.getParameter("zstudentName");
String sex = request.getParameter("zsex");
String banji = request.getParameter("zbanji");
String studentPassword = request.getParameter("zstudentPassword");
System.out.println("password : "+studentPassword);
studentManager.saveAll(studentName,studentPassword, sex, banji);
return "success";
}
public void findByName(){
int counts=0;
try {
HttpServletRequest request = ServletActionContext.getRequest();
String studentName = request.getParameter("studentName");
counts =studentManager.findByName(studentName,counts);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("count : 数值 等于 : "+ counts);
out.print(counts);
}
//验证登陆
public void findByNamePassword() {
try {
HttpServletRequest request = ServletActionContext.getRequest();
String studentName = request.getParameter("studentName");
String studentPassword = request.getParameter("studentPassword");
boolean flag = studentManager.findByNamePassword(studentName, studentPassword);
System.out.println("action flag = "+flag);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
out =response.getWriter();
out.print(flag);
} catch (IOException e) {
e.printStackTrace();
}
}
public void setRequest(Map<String, Object> request) {
this.request = request;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}
public void setStudentManager(StudentManager studentManager) {
this.studentManager = studentManager;
}
}
3.manager中的
package cn.com.kxrj.manager.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import cn.com.kxrj.dao.StudentDAO;
import cn.com.kxrj.manager.StudentManager;
import cn.com.kxrj.model.Student;
import cn.com.kxrj.tool.Pagination;
public class StudentManagerImpl implements StudentManager {
private StudentDAO studentDAO;
public void setStudentDAO(StudentDAO studentDAO) {
this.studentDAO = studentDAO;
}
//删除数据
public void deleteById(int id) {
Student model=studentDAO.findById(id);
studentDAO.delete(model);
}
//查询所有的数据
public Pagination findAll(int currPage) {
List list = new ArrayList();
Pagination pagination = new Pagination();
pagination.setCurrPage(currPage);
pagination.setPageSize(PAGESIZE);
/*********动态构造SQL***********/
StringBuffer sql= new StringBuffer(" from Student where 1=1 ");
List<Object> objval = new ArrayList<Object>();
Iterator it = objval.iterator();
Object[] values= new Object[objval.size()];
int i=0;
while(it.hasNext()){
/* Object val = it.next();
values[i]=val;*/
values[i]=it.next();
i++;
}
String hql = sql.toString();
System.out.println("hql : "+hql);
int offset = (pagination.getCurrPage()-1)*PAGESIZE;
list = studentDAO.findByPage(hql, values, offset, PAGESIZE);
pagination.setList(list);
int maxRow = studentDAO.maxRow(hql, values).size();
pagination.setMaxRow(maxRow);
return pagination;
}
public Student findByI(int id) {
// TODO Auto-generated method stub
return null;
}
public int findByName(String studentName, int counts) {
List list= studentDAO.findByName(studentName);
if(list.size()>0){
counts=1;
}
return counts;
}
public boolean findByNamePassword(String studentName, String password) {
boolean flag = false;
List list = studentDAO.findByNamePassword(studentName, password);
System.out.println("manager list "+list.size());
if(list.size()>0){
flag=true;
}
System.out.println("manager flag "+flag);
return flag;
}
public void saveAll(String studentName, String password, String sex,
String banji) {
studentDAO.insert(new Student(studentName,password,sex,banji));
}
}
4。 dao 中的 :
1.
package cn.com.kxrj.tool.impl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.com.kxrj.tool.BaseDAO;
public class BaseDAOImpl extends HibernateDaoSupport implements BaseDAO {
/**
* 使用hql语句进行分页查询
* @param hql 需要查询的hql语句
* @param values 如果hql有多个个参数需要传入,values就是传入hql的参数数组
* @param offset 第一条记录索引
* @param pageSize 每页需要显示的记录数
* @return 当前页的所有记录
*/
public List findByPage(final String hql,final Object[] values,final int offset,final int pageSize) {
List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
for(int i=0; i<values.length;i++){
query.setParameter(i, values[i]);
}
List result = query.setFirstResult(offset).setMaxResults(pageSize).list();
return result;
}
});
return list;
}
/**
* 使用hql语句进行分页查询
* @param hql 需要查询的hql语句
* @param values 如果hql有多个个参数需要传入,values就是传入hql的参数数组
* @param offset 第一条记录索引
* @param pageSize 每页需要显示的记录数
* @return 当前页的所有记录
*/
public List maxRow(final String hql,final Object[] values) {
List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql); //查询数据
for(int i=0;i<values.length;i++){
query.setParameter(i, values[i]);
}
List result= query.list();
return result;
}
});
return list;
}
}
2.package cn.com.kxrj.dao.impl;
import java.util.List;
import cn.com.kxrj.dao.StudentDAO;
import cn.com.kxrj.model.Student;
import cn.com.kxrj.tool.impl.BaseDAOImpl;
public class StudentDAOImpl extends BaseDAOImpl implements StudentDAO {
//删除学生信息
public void delete(Student model) {
this.getHibernateTemplate().delete(model);
}
//根据id 查找一条数据
public Student findById(int id) {
return (Student) this.getHibernateTemplate().get(Student.class, id);
}
//依照姓名查找
public List<Student> findByName(String studentName) {
System.out.println("学生查找dao 名字 " +studentName);
List<Student> list =this.getHibernateTemplate().find("from Student where stuname=? ", studentName);
System.out.println("dao list "+list.size());
return list;
}
//验证
public List<Student> findByNamePassword(String studentName, String studentPassword) {
return this.getHibernateTemplate().find("from Student where stuname=? and stupassword=?", new Object[]{studentName,studentPassword});
}
//保存所有的信息
public void insert(Student model) {
this.getHibernateTemplate().save(model);
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户登陆</title>
<link href="<%=basePath %>style/main.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath%>style/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath %>js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery-ui.js"></script>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
<script type="text/javascript">
function login(){
var studentName1=document.getElementById("studentName").value;
var studentPassword1 = document.getElementById("studentPasswod").value;
if(studentName1==""){
document.getElementById("yonghus").innerHTML="<font color='red'>请输入用户名!</font>";
return ;
}
if(studentPassword1==""){
document.getElementById("mimas").innerHTML="<font color='red'>请输入密码!</font>";
return ;
}
$.ajax({
type: "post",
url: "<%=basePath%>background/student!findByNamePassword",
data: 'studentName='+studentName1+'&studentPassword='+studentPassword1,
success: function(msg){
if(msg=="true"){
document.getElementById("loginForm").submit();
}else{
document.getElementById("tishi").innerHTML="<font color='red'>用户名或者密码错误。请重新输入</font>";
}
}
});
}
function yichu(){
document.getElementById("yonghus").innerHTML="";
}
function yichu1(){
document.getElementById("mimas").innerHTML="";
}
//注册
function zhuce(){
$("#addStu").dialog({title: '注册学生信息'});
return false;
}
//验证 注册信息
function checkAddStu(){
if($("#zstudentName").val()==""){
$("#zname").html("<font color='red'>请输入用户!</font>");
return;
}
if($("#zstudentPassword").val()==""){
$("#ztpassword").html("<font color='red'>请输入密码!</font>");
return;
}
if($("#zstudentPassword1").val()==""){
$("#ztpassword1").html("<font color='red'>请再次输入密码!</font>");
return;
}
if($("#zstudentPassword").val()!=$("#zstudentPassword1").val()){
$("#ztpasswordx").html("<font color='red'>两次输入密码不一致!</font>");
return;
}
if($("#zsex").val()==""){
$("#ztsex").html("<font color='red'>请输入性别!</font>");
return;
}
if($("#zbanji").val()==""){
$("#ztbanji").html("<font color='red'>请输入班级!</font>");
return;
}
$.ajax({
type: "post",
url: "<%=basePath %>background/student!findByName",
data: 'studentName='+$("#zstudentName").val(),
success: function(msg){
if(msg==0){
$("#addStuForm").submit();
}else{
$("#zname").html("<font color='red'>该用户已经存在!</font>");
}
}
});
}
//失去焦点的时候去掉末尾提示信息
function losname(){
$("#zname").html("");
}
function lospassword(){
$("#ztpassword").html("");
}
function lospassword1(){
$("#ztpassword1").html("");
}
function losbanji(){
$("#ztbanji").html("");
}
function losname(){
$("#zname").html("");
}
function loaslianci(){
$("#ztpasswordx").html("");
}
</script>
</head>
<body>
<!-- 注册学生信息 -->
<div id="addStu" style="display:none">
<form action="<%=basePath%>background/student!saveAll" id="addStuForm" method="post" >
用 户 名:
<input type="text" name="zstudentName" id="zstudentName" onblur="javacript:losname();"/> <span id="zname"></span>
<br />
<br />
密 码:
<input type="password" name="zstudentPassword" id="zstudentPassword" onblur="javacript:lospassword();" onclick="javacript:loaslianci();"/> <span id="ztpassword"></span>
<br />
<br />
确认密码:
<input type="password" name="zstudentPassword1" id="zstudentPassword1" onblur="javacript:lospassword1();" onclick="javacript:loaslianci();"/> <span id="ztpassword1"></span>
<br />
<span id="ztpasswordx"></span>
<br />
性 别:
<input type="radio" name="zsex" id="zsex" value="男" checked="checked"/>男
<input type="radio" name="zsex" id="zsex" value="女" />女
<br />
<br />
班 级:
<input type="text" name="zbanji" id="zbanji" onblur="javacript:losbanji();"/> <span id="ztbanji"></span>
<br />
<br />
<div align="center">
<a href="javascript:checkAddStu();">
<img alt="" src="<%=basePath%>image/queren.gif" border="0" />
</a>
<a href="" onclick="javascript:go: back(-1);">
<img alt="" src="<%=basePath%>image/fanhui.gif" border="0" />
</a>
</div>
</form>
</div>
<!-- 结束注册学生信息 -->
<div align="center">
<form action="<%=basePath%>background/student!findAll" id="loginForm" method="post">
<table>
<tr><td><span id="tishi"></span></td>></tr>
<br />
<br />
<br />
<br />
<br />
<tr>
<td>用户姓名:<input type="text" id="studentName" name="studentName" onblur="javascript:yichu();"/><span id="yonghus"></span></td>
</tr>
<br />
<br />
<tr>
<td>用户密码:<input type="password" id="studentPasswod" name="studentPasswod" onblur="javascript:yichu1();"/><span id="mimas"></span> </td>
</tr>
<br />
<br />
<tr>
<td> <input type="button" value="确认" onclick="javascript: login();" /> <input type="button" value="注册" onclick="javascript: zhuce();" /> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
2.action 中的
package cn.com.kxrj.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
import cn.com.kxrj.manager.StudentManager;
import cn.com.kxrj.tool.Pagination;
public class StudentAction extends ActionSupport implements RequestAware,SessionAware{
/**
*
*/
private static final long serialVersionUID = 1L;
private StudentManager studentManager;
private Map<String,Object > request;
private Map<String,Object > session;
private PrintWriter out;
public String findAll(){
HttpServletRequest request= ServletActionContext.getRequest();
String currPage=request.getParameter("currPage");
if(currPage==null||currPage.equals("")){
currPage=String.valueOf("1");
}
Pagination pagination =studentManager.findAll(Integer.valueOf(currPage));
request.setAttribute("data", pagination.getList());
request.setAttribute("currPage", pagination.getCurrPage());
request.setAttribute("maxPage", pagination.getMaxPage());
request.setAttribute("maxRow", pagination.getMaxRow());
request.setAttribute("pageSize", pagination.getPageSize());
return "student_list";
}
public String deleteById(){
HttpServletRequest request = ServletActionContext.getRequest();
String studentId = request.getParameter("studentId");
System.out.println("学生ID "+studentId);
studentManager.deleteById(Integer.valueOf(studentId));
return this.findAll();
}
public String saveAll(){
HttpServletRequest request = ServletActionContext.getRequest();
String studentName =request.getParameter("zstudentName");
String sex = request.getParameter("zsex");
String banji = request.getParameter("zbanji");
String studentPassword = request.getParameter("zstudentPassword");
System.out.println("password : "+studentPassword);
studentManager.saveAll(studentName,studentPassword, sex, banji);
return "success";
}
public void findByName(){
int counts=0;
try {
HttpServletRequest request = ServletActionContext.getRequest();
String studentName = request.getParameter("studentName");
counts =studentManager.findByName(studentName,counts);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("count : 数值 等于 : "+ counts);
out.print(counts);
}
//验证登陆
public void findByNamePassword() {
try {
HttpServletRequest request = ServletActionContext.getRequest();
String studentName = request.getParameter("studentName");
String studentPassword = request.getParameter("studentPassword");
boolean flag = studentManager.findByNamePassword(studentName, studentPassword);
System.out.println("action flag = "+flag);
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
out =response.getWriter();
out.print(flag);
} catch (IOException e) {
e.printStackTrace();
}
}
public void setRequest(Map<String, Object> request) {
this.request = request;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}
public void setStudentManager(StudentManager studentManager) {
this.studentManager = studentManager;
}
}
3.manager中的
package cn.com.kxrj.manager.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import cn.com.kxrj.dao.StudentDAO;
import cn.com.kxrj.manager.StudentManager;
import cn.com.kxrj.model.Student;
import cn.com.kxrj.tool.Pagination;
public class StudentManagerImpl implements StudentManager {
private StudentDAO studentDAO;
public void setStudentDAO(StudentDAO studentDAO) {
this.studentDAO = studentDAO;
}
//删除数据
public void deleteById(int id) {
Student model=studentDAO.findById(id);
studentDAO.delete(model);
}
//查询所有的数据
public Pagination findAll(int currPage) {
List list = new ArrayList();
Pagination pagination = new Pagination();
pagination.setCurrPage(currPage);
pagination.setPageSize(PAGESIZE);
/*********动态构造SQL***********/
StringBuffer sql= new StringBuffer(" from Student where 1=1 ");
List<Object> objval = new ArrayList<Object>();
Iterator it = objval.iterator();
Object[] values= new Object[objval.size()];
int i=0;
while(it.hasNext()){
/* Object val = it.next();
values[i]=val;*/
values[i]=it.next();
i++;
}
String hql = sql.toString();
System.out.println("hql : "+hql);
int offset = (pagination.getCurrPage()-1)*PAGESIZE;
list = studentDAO.findByPage(hql, values, offset, PAGESIZE);
pagination.setList(list);
int maxRow = studentDAO.maxRow(hql, values).size();
pagination.setMaxRow(maxRow);
return pagination;
}
public Student findByI(int id) {
// TODO Auto-generated method stub
return null;
}
public int findByName(String studentName, int counts) {
List list= studentDAO.findByName(studentName);
if(list.size()>0){
counts=1;
}
return counts;
}
public boolean findByNamePassword(String studentName, String password) {
boolean flag = false;
List list = studentDAO.findByNamePassword(studentName, password);
System.out.println("manager list "+list.size());
if(list.size()>0){
flag=true;
}
System.out.println("manager flag "+flag);
return flag;
}
public void saveAll(String studentName, String password, String sex,
String banji) {
studentDAO.insert(new Student(studentName,password,sex,banji));
}
}
4。 dao 中的 :
1.
package cn.com.kxrj.tool.impl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.com.kxrj.tool.BaseDAO;
public class BaseDAOImpl extends HibernateDaoSupport implements BaseDAO {
/**
* 使用hql语句进行分页查询
* @param hql 需要查询的hql语句
* @param values 如果hql有多个个参数需要传入,values就是传入hql的参数数组
* @param offset 第一条记录索引
* @param pageSize 每页需要显示的记录数
* @return 当前页的所有记录
*/
public List findByPage(final String hql,final Object[] values,final int offset,final int pageSize) {
List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql);
for(int i=0; i<values.length;i++){
query.setParameter(i, values[i]);
}
List result = query.setFirstResult(offset).setMaxResults(pageSize).list();
return result;
}
});
return list;
}
/**
* 使用hql语句进行分页查询
* @param hql 需要查询的hql语句
* @param values 如果hql有多个个参数需要传入,values就是传入hql的参数数组
* @param offset 第一条记录索引
* @param pageSize 每页需要显示的记录数
* @return 当前页的所有记录
*/
public List maxRow(final String hql,final Object[] values) {
List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query = session.createQuery(hql); //查询数据
for(int i=0;i<values.length;i++){
query.setParameter(i, values[i]);
}
List result= query.list();
return result;
}
});
return list;
}
}
2.package cn.com.kxrj.dao.impl;
import java.util.List;
import cn.com.kxrj.dao.StudentDAO;
import cn.com.kxrj.model.Student;
import cn.com.kxrj.tool.impl.BaseDAOImpl;
public class StudentDAOImpl extends BaseDAOImpl implements StudentDAO {
//删除学生信息
public void delete(Student model) {
this.getHibernateTemplate().delete(model);
}
//根据id 查找一条数据
public Student findById(int id) {
return (Student) this.getHibernateTemplate().get(Student.class, id);
}
//依照姓名查找
public List<Student> findByName(String studentName) {
System.out.println("学生查找dao 名字 " +studentName);
List<Student> list =this.getHibernateTemplate().find("from Student where stuname=? ", studentName);
System.out.println("dao list "+list.size());
return list;
}
//验证
public List<Student> findByNamePassword(String studentName, String studentPassword) {
return this.getHibernateTemplate().find("from Student where stuname=? and stupassword=?", new Object[]{studentName,studentPassword});
}
//保存所有的信息
public void insert(Student model) {
this.getHibernateTemplate().save(model);
}
}
发表评论
-
S2SI
2013-04-17 19:57 557简单的struts2+spring+ibatis 实现增删改查 ... -
tapestry 初学 转载
2011-05-30 12:52 13161、web.xml 一般来说,使用Tapestry需要在Tap ... -
jsp中JSTL应用
2011-04-28 11:40 844截取字的长度 [/align][align=left] & ... -
实现s1sh
2010-12-15 10:27 962ation package cn.com.webapp. ... -
初级s1ssh
2010-12-15 10:25 743web中 <?xml version="1.0 ... -
s2pshixian
2010-12-14 21:10 742action zhong public class Ne ... -
s2p
2010-12-14 20:58 960<?xml version="1.0" ... -
初级 ssh jar包
2010-12-14 20:43 673jar包图片格式 -
初级S2SH配置文件
2010-12-14 20:30 8761。web.xml: <?xml version=& ...
相关推荐
4. 权限分配:GRANT、DENY和REVOKE语句用于赋予、拒绝和撤销用户对数据库对象(如表、视图、存储过程等)的访问权限。这允许你精确控制用户能做什么,不能做什么。 5. 触发器和审计:为了更精细的控制和日志记录,...
【初级根文件系统的制作】是...总的来说,制作初级根文件系统是一个涉及内核启动流程理解、工具选择和编译、目录结构规划以及依赖管理的过程。通过不断试验和优化,可以构建出适合特定设备的高效、精简的根文件系统。
该示例主要演示了如何使用UiBot自动登录163邮箱的过程: 1. **用户输入**:通过`Dialog.InputBox`函数获取用户名和密码。 2. **打开Excel文件**:利用`Excel.OpenExcel`函数打开位于桌面的“UiBotʵ.xls”文件,并将...
4. **用户验证**: 登录过程的核心是验证用户输入的用户名和密码是否匹配数据库中的记录。这通常通过执行SQL的`SELECT`查询实现,如果找到匹配的记录,则验证成功;否则,返回错误信息。 5. **密码安全性**: 虽然这...
例如,一个登录页面可能使用Request对象接收用户输入,然后将验证后的用户信息存入Session,以便在后续的受保护页面中检查用户身份。 学习这部分内容,有助于初学者建立起对JSP基本概念的理解,并为更深入的Web开发...
本项目名为"Web初级项目",主要是一个超市管理系统,它涵盖了从数据库设计、后端开发到前端交互的全过程,旨在帮助学习者掌握基础的Web开发技能。 1. 数据库设计:在系统设计初期,首先需要考虑的是数据存储。在这...
同时,实践项目是巩固理论知识的最好方式,可以尝试创建简单的Web应用,如用户注册登录系统或小型博客,以此来提升自己的动手能力。在学习过程中,结合官方文档、在线教程和社区资源,可以加快学习进度并解决遇到的...
这一点强调了从初级到中级再到高级逐步深入的认证路径。 5. 原厂安装服务与自行安装: 文档中提到,通过中级认证考试后,用户可以不必选择价格较高的原厂安装服务。这是因为用户通过系统学习已经具备了足够的技术...
同时,介绍了UNIX中的用户登录过程,以及如何正确地修改用户密码、退出系统等操作。 本书的内容主要针对UNIX系统的初学者,但通过阅读和实践,即便是有一定经验的用户也能从中获得系统学习UNIX的机会。此外,本书...
### NIT-Pro初级软件工程师(Java)案例题知识点解析 #### 一、考试概况与要求 **考试科目**: 初级软件工程师(Java) **考试时间**: 6小时 **考试说明**: - 本试卷案例包含两个任务,考生需完成其中一个。 - ...
1. **登录鉴别**:确保登录操作系统和数据库系统的用户都经过身份标识和鉴别的过程。 2. **口令安全性**: - 口令应由数字、大小写字母和特殊符号组成。 - 长度至少为8位,推荐使用更长的口令,至少12位。 - 至少...
【ASP.NET初级面试题2】涉及的知识点涵盖了ASP.NET的基础概念、编程模型、数据库操作、XML处理、Web开发、网络通信、SOA平台和服务、协作和质量管理等方面。以下是这些知识点的详细说明: **基础概念与编程模型** 1...
### MySQL初级与高级教程知识点概览 #### 一、MySQL基础知识 1. **数据库系统概述** - 数据库系统的组成:数据库(Data)、数据库管理系统(DBMS)、数据库管理员(DBA)。 - 关系型数据库特点:通过表格形式来...
### 软件测试初级工程师面试题解析 #### 岗位职责与任职要求解析 - **岗位职责**主要包括: 1. **编写测试用例**:根据项目的需求文档和设计文档,制定详细的测试策略和用例。 2. **搭建测试环境**:根据测试...
2. **Linux安装**:讲解如何下载和安装各种Linux发行版,包括Live CD/DVD启动和硬盘安装过程,以及分区策略。 3. **Linux桌面环境**:介绍常见的桌面环境,如GNOME、KDE、XFCE等,以及如何定制工作环境。 4. **...
Linux是世界上最受欢迎的开源操作...本“Linux完整教程(初级教程)”将引导新手逐步探索这个丰富的世界,从安装Linux到日常使用,再到更高级的系统管理和开发工作。通过学习,你可以更好地理解和利用Linux的强大功能。
在“SpringMVC入门->网站的初级框架”中,我们将探讨如何使用SpringMVC构建一个简单的网站登录功能。 首先,我们需要理解SpringMVC的工作流程。当用户通过浏览器发送一个HTTP请求到`localhost:8080/ws/web/login`...
### 初级程序员面试资料详解 #### C#与C/C++基础知识 **1. C#中property与attribute的区别** - **Property(属性)**: 在C#中,`property`是面向对象编程的一个重要特性,它使得类的成员可以通过类似于字段的方式...
### 组态王6.53初级培训教程知识点解析 ...通过本教程的学习,不仅可以了解组态王的基本概念和架构,还能掌握从创建新工程到实现复杂监控功能的全过程。这对于从事工业自动化领域的技术人员来说是非常宝贵的资源。