用户注册功能
1、可以先判断登录名是否已经存在
2、要给密码使用MD5进行加密操作
用户登录功能
1、登录功能要注意先给密码加密后,在进行查询
密码加密后再查询
用户的状态必须是1,字符串类型的
用户退出功能
1、把用户信息从HttpSession中清除
查询所有客户功能
1、数据字典表的引入
数据字典表的作用:规范开发中数据的写法
字段表与客户表是一对多的关系
修改客户表,添加外键(使用SQLyog进行修改)
2、创建字典表的实体和映射的配置文件
编写字典表的JavaBean和映射的配置文件
修改Customer的JavaBean,因为是多方,需要把外键字段换成字典对象
修改Customer.hbm.xml的配置文件,配置一对多
3、分页查询所有的客户功能实现
按条件查询所有的客户
1、使用异步的方式加载客户级别和客户的来源
前端使用Jquery的ajax技术
后端使用fastjson的jar包
导入fastjson的开发jar包
String s = JSON.toJSONString(集合)
String s = JSON.toJSONString(对象)
如果List集合中存入相同引用的对象
fastjson默认的情况下是进行循环检测的,去除掉死循环调用的方式
可以使用JSON.toJSONString(p,SerializerFeature.DisableCircularReferenceDetect)
去除循环检测,但是就会出现死循环的效果
最后可以使用注解:@JSONField(serialize=false)对指定的属性不转换成json
MD5Utils
public class MD5Utils {
/**
* 使用md5的算法进行加密
*/
public static String md5(String plainText) {
byte[] secretBytes = null;
try {
secretBytes = MessageDigest.getInstance("md5").digest(
plainText.getBytes());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("没有md5这个算法!");
}
String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
// 如果生成数字未满32位,需要前面补0
for (int i = 0; i < 32 - md5code.length(); i++) {
md5code = "0" + md5code;
}
return md5code;
}
public static void main(String[] args) {
System.out.println(md5("123"));
}
}
PageBean
/**
* 分页的JavaBean
* @author Administrator
*/
public class PageBean<T> {
// 当前页
private int pageCode;
// 总页数
// private int totalPage;
// 总记录数
private int totalCount;
// 每页显示的记录条数
private int pageSize;
// 每页显示的数据
private List<T> beanList;
public int getPageCode() {
return pageCode;
}
public void setPageCode(int pageCode) {
this.pageCode = pageCode;
}
/**
* 调用getTotalPage() 获取到总页数
* JavaBean的属性规定:totalPage是JavaBean是属性 ${pageBean.totalPage}
* @return
*/
public int getTotalPage() {
// 计算
int totalPage = totalCount / pageSize;
// 说明整除
if(totalCount % pageSize == 0){
return totalPage;
}else{
return totalPage + 1;
}
}
/*public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}*/
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List<T> getBeanList() {
return beanList;
}
public void setBeanList(List<T> beanList) {
this.beanList = beanList;
}
}
CustomerDaoImpl
/**
* 分页的查询
*/
public PageBean<Customer> findByPage(Integer pageCode, Integer pageSize, DetachedCriteria criteria) {
PageBean<Customer> page = new PageBean<Customer>();
page.setPageCode(pageCode);
page.setPageSize(pageSize);
//先查询总记录数 select count(*)
criteria.setProjection(Projections.rowCount());
List<Number> list = (List<Number>) this.getHibernateTemplate().findByCriteria(criteria);
if(list!=null && list.size()>0){
int totalCount = list.get(0).intValue();
//总的记录数
page.setTotalCount(totalCount);
}
//强调:把select count(*)先清空 变成select * ...
criteria.setProjection(null);
//提供分页的查询 pageCode 当前页
List<Customer> beanList = (List<Customer>) this.getHibernateTemplate().findByCriteria(criteria, (pageCode-1)*pageSize, pageSize);
//分页查询数据,每页显示的数据 使用limit
page.setBeanList(beanList);
return page;
}
CustomerAction
//属性驱动的方式
//当前页,默认值就1
private Integer pageCode= 1;
public void setPageCode(Integer pageCode) {
if(pageCode== null){
pageCode = 1;
}
this.pageCode = pageCode;
}
//每页显示的数据的条数
private Integer pageSize = 2;
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
/**
* 分页的查询方法
* @return
*/
public String findByPage(){
//调用service业务层
DetachedCriteria criteria = DetachedCriteria.forClass(Customer.class);
//查询
PageBean<Customer> page = customerService.findByPage(pageCode,pageSize,criteria);
//压栈
ValueStack vs = ActionContext.getContext().getValueStack();
//栈顶是map<"page",page对象>
vs.set("page", page);
return "page";
}
list.jsp
<SCRIPT language=javascript>
//提交分页的查询表单
function to_page(page){
if(page){
$("#page").val(page);
}
document.customerForm.submit();
}
</SCRIPT>
<c:forEach items="${page.beanList}" var="customer">
<TR
style="FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none">
<TD>${customer.cust_name }</TD>
<TD>${customer.level.dict_item_name }</TD>
<TD>${customer.source.dict_item_name }</TD>
<TD>${customer.cust_linkman }</TD>
<TD>${customer.cust_phone }</TD>
<TD>${customer.cust_mobile }</TD>
<TD>
<a href="${pageContext.request.contextPath }/customerServlet?method=edit&custId=${customer.cust_id}">修改</a>
<a href="${pageContext.request.contextPath }/customerServlet?method=delete&custId=${customer.cust_id}">删除</a>
</TD>
</TR>
</c:forEach>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD><SPAN id=pagelink>
<DIV
style="LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: right">
共[<B>${page.totalCount}</B>]条记录,共[<B>${page.totalPage}</B>]页
,每页显示
<select name="pageSize">
<option value="2" <c:if test="${page.pageSize==2 }">selected</c:if>>2</option>
<option value="3" <c:if test="${page.pageSize==3 }">selected</c:if>>3</option>
</select>
条
<c:if test="${page.pageCode>1 }">
[<A href="javascript:to_page(${page.pageCode-1})">前一页</A>]
</c:if>
<B>${page.pageCode}</B>
<c:if test="${page.pageCode<page.totalPage }">
[<A href="javascript:to_page(${page.pageCode+1})">后一页</A>]
</c:if>
到
<input type="text" size="3" id="page" name="pageCode" />
页
<input type="button" value="Go" onclick="to_page()"/>
</DIV>
</SPAN></TD>
</TR>