当前位置:网站首页>Customize MVC 3.0
Customize MVC 3.0
2022-07-24 06:27:00 【zsm030616】
Catalog
- 1. Make the frame into jar package , Then import the new project , And the dependence of the framework jar Import the package
- 2. Paging label related files 、 And related helper classes
- 3. Add the configuration file of the framework 、 as well as web.xml Configuration of
- 4. complete Book Entity class and bookDao Compiling
- 5. Complete the general addition, deletion and modification methods
1. Make the frame into jar package , Then import the new project , And the dependence of the framework jar Import the package






2. Paging label related files 、 And related helper classes
3. Add the configuration file of the framework 、 as well as web.xml Configuration of
4. complete Book Entity class and bookDao Compiling
package com.zsm.entity;
public class Book {
private int bid;
private String bname;
private float price;
public Book() {
// TODO Auto-generated constructor stub
}
public int getBid() {
return bid;
}
public void setBid(int bid) {
this.bid = bid;
}
public String getBname() {
return bname;
}
public void setBname(String bname) {
this.bname = bname;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public Book(int bid, String bname, float price) {
super();
this.bid = bid;
this.bname = bname;
this.price = price;
}
@Override
public String toString() {
return "Book [bid=" + bid + ", bname=" + bname + ", price=" + price + "]";
}
}
package com.zsm.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.zsm.entity.Book;
import com.zsm.util.BaseDao;
import com.zsm.util.DBAccess;
import com.zsm.util.PageBean;
import com.zsm.util.StringUtils;
public class BookDao extends BaseDao<Book>{
// Inquire about
public List<Book> list(Book book,PageBean pageBean) throws Exception{
String sql="select * from t_mvc_book where 1=1";
String bname = book.getBname();
if(StringUtils.isNotBlank(bname)) {
sql+=" and bname like '%"+bname+"%'";
}
int bid = book.getBid();
// The front desk jsp Pass it to the background , As long as it's passed, it's worth it , Not wearing it is the default , The default value is 0
if(bid!=0) {
sql+=" and bid = "+bid;
}
return super.executeQuery(sql, pageBean, rs ->{
List<Book> list=new ArrayList<>();
try {
while(rs.next()) {
list.add(new Book(rs.getInt("bid"),rs.getString("bname"),rs.getFloat("price")));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
});
}
// increase
public int add(Book book) throws Exception {
Connection con = DBAccess.getConnection();
String sql="insert into t_mvc_book values (?,?,?)";
PreparedStatement pst = con.prepareStatement(sql);
pst.setObject(1, book.getBid());
pst.setObject(2, book.getBname());
pst.setObject(3, book.getPrice());
return pst.executeUpdate();
}
// Delete
public int del(Book book) throws Exception {
Connection con = DBAccess.getConnection();
String sql="delete from t_mvc_book where bid= ?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setObject(1, book.getBid());
return pst.executeUpdate();
}
// Change
public int edit(Book book) throws Exception {
Connection con = DBAccess.getConnection();
String sql="update t_mvc_book set bname=?,price=?, where bid=?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setObject(3, book.getBid());
pst.setObject(1, book.getBname());
pst.setObject(2, book.getPrice());
return pst.executeUpdate();
}
}
And then use junit4 To test
Then it will automatically generate a BookDaoTest:
package com.zsm.dao;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.zsm.entity.Book;
public class BookDaoTest {
private BookDao bookDao=new BookDao();
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testList() {
try {
List<Book> list = bookDao.list(new Book(), null);
for (Book book : list) {
System.out.println(book);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
public void testAdd() {
fail("Not yet implemented");
}
@Test
public void testDel() {
fail("Not yet implemented");
}
@Test
public void testEdit() {
fail("Not yet implemented");
}
}
5. Complete the general addition, deletion and modification methods
Paging query :
@Test
public void testList() {
try {
List<Book> list = bookDao.list(new Book(), new PageBean());
for (Book book : list) {
System.out.println(book);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
increase
@Test
public void testAdd() {
Book book = new Book(1234321, "1234321", 1234321);
try {
bookDao.add(book);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Change
@Test
public void testEdit() {
Book book = new Book(1234321, "123432100", 1234321);
try {
bookDao.edit(book);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Delete
@Test
public void testDel() {
Book book = new Book(1234321, "1234321", 1234321);
try {
bookDao.del(book);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
边栏推荐
- [219] what is the difference between app testing and web testing?
- Homework in the second week
- leetcode剑指offer JZ42 连续子数组的最大和
- [222] memory overflow and location
- IA笔记 1
- 三分钟记住20道性能测试经典面试题
- Flink function (2): checkpointedfunction
- MySQL从基础到入门到高可用
- Metersphere one stop open source continuous testing platform
- 【214】什么是自动化框架
猜你喜欢

IP notes (6)

IA课总结(2)

Polkadot | interprets how liberty plan, which subverts traditional social media, will be launched in Poka

IP job (6)

Using keras and LSTM to realize time series prediction of long-term trend memory -lstnet

一批面试题及答案_20180403最新整理

IP课笔记(4)

Heap overflow of kernel PWN basic tutorial

Leetcode sword finger offer jz73 flip word sequence

Leetcode sword finger offer JZ9 dual stack implementation queue
随机推荐
Using keras to realize LSTM time series prediction based on attention mechanism
剑指offer JZ10斐波那契数列
IP笔记(12)
Data warehouse and data warehouse modeling
Jenkins automated unattended operation (up / down)
IA课总结(1)
Luckyframeweb testing platform (a full latitude free open source testing platform that supports interface automation, Web UI automation, APP automation, and distributed testing)
手动安装Apache
IP job (6)
Machine learning & deep learning introduction information sharing summary
[no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
Map the intranet to the public network [no public IP required]
[test tool]
进程和计划任务管理
Unity shader: realize diffuse reflection and specular reflection
IP笔记(7)
Leetcode refers to the duplicate number in the offer jz3 array
IP course (OSPF) comprehensive experiment
Hololens2 development: use MRTK and simulate eye tracking
Batch operation of generating MySQL statements from Excel