开发工具Eclipse的使用之导入项目(import)

🥳🥳**Welcome Huihui's Code World ! !**🥳🥳

接下来看看由辉辉所写的关于Eclipse使用的相关操作吧

目录

[🥳🥳Welcome Huihui's Code World ! !🥳🥳](#🥳🥳Welcome Huihui's Code World ! !🥳🥳)

一.导读

二.详细操作步骤

1.右击项目处,点击import

2.选择所要导入的项目所在路径

3.导入项目完毕之后,需要检查是否有错误

4.若报错,则检查配置的文件是否出现了问题

5.将报错的文件移除掉

6.重新配置一个文件(注意版本)

7.项目不报错之后,我们来看一下数据库辅助类​编辑

8.核对账号密码的信息

9.再选择需要导入的对应数据库脚本

10.选择运行的jsp界面即可,若成功运行,则没有问题

11.我们再参照这个项目中的代码,完成一个简单的增删改查

entity

dao

servlet

运行结果


一.导读

上篇我们已经详细介绍了开发工具eclipse,也说明了eclipse的基本使用,那么我们这篇来详细讲述一下怎么导入项目

二.详细操作步骤

1.右击项目处,点击import

2.选择所要导入的项目所在路径

3.导入项目完毕之后,需要检查是否有错误

4.若报错,则检查配置的文件是否出现了问题

5.将报错的文件移除掉

6.重新配置一个文件(注意版本)

7.项目不报错之后,我们来看一下数据库辅助类

8.核对账号密码的信息

9.再选择需要导入的对应数据库脚本

10.选择运行的jsp界面即可,若成功运行,则没有问题

11.我们再参照这个项目中的代码,完成一个简单的增删改查

entity

java 复制代码
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

java 复制代码
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<Cat>{
	public List<Cat> 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

java 复制代码
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<Cat>{
	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<Cat> 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<Cat> list = catDao.list(cat, null);
				req.setAttribute("c", list.get(0));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return "toEdit";
	}
}

运行结果

好啦,今天的分享就到这了,希望能够帮到你呢!😊😊

相关推荐
你不是我我1 小时前
【Java 开发日记】HTTP3 性能更好,为什么内网微服务依然多用 HTTP2?HTTP2 内网优势是什么?
java·开发语言·微服务
雪碧聊技术1 小时前
大模型爆火!Java后端如何抓住Agent全栈开发的风口
java·大模型·agent·全栈开发
逻辑驱动的ken2 小时前
Java高频面试场景题25
java·开发语言·深度学习·面试·职场和发展
AI人工智能+电脑小能手3 小时前
【大白话说Java面试题】【Java基础篇】第32题:Java的异常处理机制是什么
java·开发语言·后端·面试
wdfk_prog4 小时前
正常关闭虚拟机时,不要点“关机”,而要点“关闭客户机”
linux·c语言·网络·ide·vscode
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ5 小时前
通过java后端代码来实现给word内容补充格式文本内容控件,以及 设置控件的标记和标题
java·c#·word
無限進步D5 小时前
Java 面向对象高级 接口
java·开发语言
逸Y 仙X6 小时前
文章二十七:ElasticSearch ES查询模板(Search Template)高效复用实战
java·大数据·数据库·elasticsearch·搜索引擎·全文检索
二哈赛车手6 小时前
新人笔记---Spring AI的Advisor以及其底层机制讲解(涉及源码),包含一些遇见的Spring AI的Advisor缺陷问题的解决方案
java·人工智能·spring boot·笔记·spring