目录
mymvcdemo是自定义mvc框架的使用示例
1.1 实体类
1.2 dao方法
1.3 写Service / biz 三层架构
1.4 建action 相当于selvert
1.5 con连接MySQL 8.0 版本
1.6 配置文件 XML
1.7 主界面布局
1.8 增加界面布局
1.9 写tld配置文件
2.0 注意架包 我是已经打包好的
package com.zking.mymvc.entity;
import java.io.Serializable;
public class Book implements Serializable {
private Integer bookid;
private String bookname;
private String bookname_pinyin;
private Float price;
private String booktype;
public Integer getBookid() {
return bookid;
}
public void setBookid(Integer bookid) {
this.bookid = bookid;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public String getBookname_pinyin() {
return bookname_pinyin;
}
public void setBookname_pinyin(String bookname_pinyin) {
this.bookname_pinyin = bookname_pinyin;
}
public Float getPrice() {
return price;
}
public void setPrice(Float price) {
this.price = price;
}
public String getBooktype() {
return booktype;
}
public void setBooktype(String booktype) {
this.booktype = booktype;
}
public Book() {
// TODO Auto-generated constructor stub
}
public Book(Integer bookid, String bookname, String bookname_pinyin, Float price, String booktype) {
super();
this.bookid = bookid;
this.bookname = bookname;
this.bookname_pinyin = bookname_pinyin;
this.price = price;
this.booktype = booktype;
}
public Book( String bookname, String bookname_pinyin, Float price, String booktype) {
this.bookname = bookname;
this.bookname_pinyin = bookname_pinyin;
this.price = price;
this.booktype = booktype;
}
@Override
public String toString() {
return "Book [bookid=" + bookid + ", bookname=" + bookname + ", bookname_pinyin=" + bookname_pinyin + ", price="
+ price + ", booktype=" + booktype + "]";
}
}
package com.zking.mymvc.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import com.zking.dao.BaseDao02;
import com.zking.dao.BaseDao02.ICovent;
import com.zking.mymvc.entity.Book;
import com.zking.util.DBHelper;
import com.zking.util.PageBean;
import com.zking.util.PinYinUtil;
public class BookDao implements IBookDao {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
@Override
public List getBooks(Book book, PageBean pageBean) {
String sql="select * from tb_book where 1=1";
List
package com.zking.mymvc.dao;
import java.util.List;
import com.zking.mymvc.entity.Book;
import com.zking.util.PageBean;
public interface IBookDao {
/**
* 查询方法
* @param book
* @param pageBean
* @return
*/
List getBooks(Book book, PageBean pageBean);
/**
* 增加方法
* @param book
*/
void addBook(Book book);
/**
* 删除方法
* @param bookid
* @return
*/
int deleteBook(int bookid);
}
package com.zking.mymvc.service;
import java.util.List;
import com.zking.mymvc.dao.BookDao;
import com.zking.mymvc.dao.IBookDao;
import com.zking.mymvc.entity.Book;
import com.zking.util.PageBean;
/**
* @author PC
*
*/
public class BookService implements IBookService {
private IBookDao dao = new BookDao();
@Override
public List getBooks(Book book,PageBean pageBean) {
return dao.getBooks(book, pageBean);
}
@Override
public void addBook(Book book) {
dao.addBook(book);
}
@Override
public void deleteBook(int bookid) {
dao.deleteBook(bookid);
}
}
package com.zking.mymvc.service;
import java.util.List;
import com.zking.mymvc.entity.Book;
import com.zking.util.PageBean;
public interface IBookService {
List getBooks(Book book,PageBean pageBean);
void addBook(Book book);
void deleteBook(int bookid);
}
package com.zking.mymvc.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zking.framework.AbstractDispatchAction;
import com.zking.framework.ModelDrive;
import com.zking.mymvc.entity.Book;
import com.zking.mymvc.service.BookService;
import com.zking.mymvc.service.IBookService;
import com.zking.util.PageBean;
public class BookAction extends AbstractDispatchAction implements ModelDrive {
private Book book = new Book();
@Override
public Object getModel() {
return book;
}
//查询
private IBookService service = new BookService();
public String getBooks(HttpServletRequest req,HttpServletResponse resp) {
PageBean pageBean = new PageBean();
pageBean.setRequest(req);
pageBean.setRows(5);
List bookPager = service.getBooks(book, pageBean);
req.setAttribute("bookPager", bookPager);
return "book";
}
/**
* 增加
* @param req
* @param resp
* @return
*/
public String addBook(HttpServletRequest req,HttpServletResponse resp) {
service.addBook(book);
return "success";
}
/**
* 删除
* @param req
* @param resp
* @return
*/
public String deleteBook(HttpServletRequest req,HttpServletResponse resp) {
service.deleteBook(book.getBookid());
return "ok";
}
}
#oracle9i
#driver=oracle.jdbc.driver.OracleDriver
#url=jdbc:oracle:thin:@localhost:1521:orcl
#user=scott
#pwd=123
#sql2005
#driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
#url=jdbc:sqlserver://localhost:1433;DatabaseName=test1
#user=sa
#pwd=123
#sql2000
#driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
#url=jdbc:microsoft:sqlserver://localhost:1433;databaseName=unit6DB
#user=sa
#pwd=888888
#mysql
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/tb_books?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
#url=jdbc:mysql://119.23.46.143:3306/db_s2_easyui?useUnicode=true&characterEncoding=UTF-8&useSSL=false
user=root
pwd=123456
]>
<%@page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="z" uri="/zking"%>
通用分页案例书本信息
书本信息
书本编号
书本名字
书本拼音
书本价格
书本类型
操作增加
${b.bookid}
${b.bookname}
${b.bookname_pinyin}
${b.price}
${b.booktype}
删除
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here
增加
1.0
1.2
Simple Tags
/zking
paging
com.zking.tag.PagingTag
empty
pageBean
true
true