资源简介
小型图书管理系统
用的是SSH框架写的
基于Struts2+Spring+Hibernate+Mysql架构
代码片段和文件信息
package com.hpit.action;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.alibaba.fastjson.JSON;
import com.hpit.bean.Book;
import com.hpit.bean.BookType;
import com.hpit.service.BookService;
import com.hpit.service.BookTypeService;
import com.hpit.util.PageBean;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
* @author 作者:12845
* @version 创建时间:2017年12月14日
* 说明:
*/
public class BookAction extends ActionSupport implements ModelDriven{
private static final long serialVersionUID = 1L;
private Book book = new Book();
@Override
public Book getModel() {
return book;
}
private BookTypeService bookTypeService;
public void setBookTypeService(BookTypeService bookTypeService) {
this.bookTypeService = bookTypeService;
}
private BookService bookService;
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
//条件
private Integer type;
private String bookName;
private Integer pageNo;
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public Integer getPageNo() {
return pageNo;
}
public void setPageNo(Integer pageNo) {
this.pageNo = pageNo;
}
public String getBookByPage() {
/*System.out.println(“type “+this.getType());
System.out.println(“bookName “+this.getBookName());
System.out.println(“pageNo “+this.getPageNo());*/
Mapject> map = new HashMapject>();
StringBuffer sb = new StringBuffer();
sb.append(“from Book where 1=1 “);
if (this.getType()!=null&&this.getType()!=-1) {
sb.append(“ and bookType.id=:type “);
map.put(“type“ this.getType());
}
if (this.getBookName()!=null&&!this.getBookName().trim().equals(““)) {
sb.append(“ and name like:bookName “);
map.put(“bookName“ “%“+this.getBookName()+“%“);
}
String row_hql=“select count(*) “+sb.toString();
String list_hql=sb.toString();
Integer pageSize=3;
PageBean pb = bookService.getBookByPage(row_hql list_hql this.getPageNo() pageSize map);
ServletActionContext.getRequest().getSession().setAttribute(“pb“ pb);
List bList = bookTypeService.getBookTypeList();
ServletActionContext.getRequest().getSession().setAttribute(“typeList“ bList);
return “success“;
}
public void typelist() throws IOException {
ServletActionContext.getResponse().setContentType(“allication/json;charset=UTF-8“);
List bList = bookTypeService.getBookTypeList();
String jsonStr=JSON.toJSONString(bList);
ServletActionContext.getResponse().getWriter().println(jsonStr);
}
//提示成功信息
private Mapject> m
- 上一篇:RTEX设计资料大全
- 下一篇:MYSQL5.0绿色版
评论
共有 条评论