Welcome Huihui's Code World ! !
接下来看看由辉辉所写的关于Eclipse使用的相关操作吧
上篇我们已经详细介绍了开发工具eclipse,也说明了eclipse的基本使用,那么我们这篇来详细讲述一下怎么导入项目
1.右击项目处,点击import
2.选择所要导入的项目所在路径
3.导入项目完毕之后,需要检查是否有错误
4.若报错,则检查配置的文件是否出现了问题
5.将报错的文件移除掉
6.重新配置一个文件(注意版本)
7.项目不报错之后,我们来看一下数据库辅助类
8.核对账号密码的信息
9.再选择需要导入的对应数据库脚本
10.选择运行的jsp界面即可,若成功运行,则没有问题
11.我们再参照这个项目中的代码,完成一个简单的增删改查
entity
package com.wh.entity; public class Cat { int cid; String cname; int age; public Cat() { // TODO Auto-generated constructor stub } public Cat(int cid, String cname, int age) { super(); this.cid = cid; this.cname = cname; this.age = age; } public int getCid() { return cid; } public void setCid(int cid) { this.cid = cid; } public String getCname() { return cname; } public void setCname(String cname) { this.cname = cname; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Cat [cid=" + cid + ", cname=" + cname + ", age=" + age + "]"; } }
dao
package com.wh.dao; import java.util.List; import com.zking.util.BaseDao; import com.zking.util.PageBean; import com.zking.util.StringUtils; public class CatDao extends BaseDao
{ public List list(Cat cat,PageBean pageBean) throws Exception{ String sql = "select * from t_mvc_cat where 1 =1 "; String title = cat.getCname(); int id = cat.getCid(); if(StringUtils.isNotBlank(title)) { sql += " and title like '%"+title+"%'"; } if(id != 0) { sql += " and cid = "+id; } return super.executeQuery(sql, Cat.class, pageBean); } public void add(Cat cat) throws Exception { String sql = "insert into t_mvc_cat(cid,cname,age) values(?,?,?)"; super.executeUpdate(sql, cat, new String[] {"cid","cname","age"}); } public void delete(Cat cat) throws Exception { String sql = "delete from t_mvc_cat where cid = ?"; super.executeUpdate(sql, cat, new String[] {"cid"}); } public void edit(Cat cat) throws Exception { String sql = "update t_mvc_cat set cname = ?,age = ? where cid = ?"; super.executeUpdate(sql, cat, new String[] {"cname","age","cid"}); } } servlet
package com.wh.web; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.wh.dao.CatDao; import com.zking.entity.Cat; import com.zking.framework.ActionSupport; import com.zking.framework.ModelDriver; import com.zking.util.PageBean; public class CatAction extends ActionSupport implements ModelDriver
{ public Cat cat = new Cat(); public CatDao catDao = new CatDao(); @Override public Cat getModel() { return cat; } public String list(HttpServletRequest req, HttpServletResponse resp) { // 查数据库的 PageBean pageBean = new PageBean(); pageBean.setRequest(req); try { List list = catDao.list(cat, pageBean); req.setAttribute("cats", list); req.setAttribute("pageBean", pageBean); } catch (Exception e) { e.printStackTrace(); } return "list"; } public String add(HttpServletRequest req, HttpServletResponse resp) { try { catDao.add(cat); } catch (Exception e) { e.printStackTrace(); } return "toList"; } public String delete(HttpServletRequest req, HttpServletResponse resp) { try { catDao.delete(cat); } catch (Exception e) { e.printStackTrace(); } return "toList"; } public String edit(HttpServletRequest req, HttpServletResponse resp) { try { catDao.edit(cat); } catch (Exception e) { e.printStackTrace(); } return "toList"; } public String toEdit(HttpServletRequest req, HttpServletResponse resp) { if(cat.getCid()!= 0) { try { List list = catDao.list(cat, null); req.setAttribute("c", list.get(0)); } catch (Exception e) { e.printStackTrace(); } } return "toEdit"; } } 运行结果
好啦,今天的分享就到这了,希望能够帮到你呢!