html综合管理
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>html综合案例</title>
</head>
<body>
<div>
<table width="100%">
<tr>
<td>千锋教育-稀有的坚持全程面授品质的大型IT教育机构</td>
<td align="right">
<a>好程序员特训营 </a>
<a>JavaEE分布式开发 </a>
<a>avaSE核心基础 </a>
<a>加入我们 </a>
</td>
</tr>
<tr>
<td >
<img src="img/new_logo.png"/>
</td>
<td align="right">
<img src="img/nav_r_ico.png" />
</td>
</tr>
<tr >
<td align="center" colspan="2">
<hr />
<span>首页 </span>
<span>课程培训 </span>
<span>教学保障 </span>
<span>免费视频 </span>
<span>公开课 </span>
<span>企业合作 </span>
<span>就业喜报 </span>
<span>学员天地 </span>
<span>关于千锋 </span>
<span>加入我们</span>
<hr />
</td>
</tr>
<tr>
<td align="right" colspan="2">
首页>课程培训>JavaEE列表
</td>
</tr>
<tr>
<td colspan="2">
<h3>课程培训</h3>
<h4>共108种课程内容</h4>
<hr />
</td>
</tr>
<tr>
<td colspan="2">
<img src="img/001.png" width="100%"/>
</td>
</tr>
</table>
</div>
<div>
<table width="100%">
<tr>
<td align="center">
<img src="img/002.png" />
</td>
<td align="center">
<img src="img/003.png" />
</td>
<td align="center">
<img src="img/004.png" />
</td>
<td align="center">
<img src="img/005.png" />
</td>
<td align="center">
<img src="img/006.png" />
</td>
</tr>
<tr>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
</tr>
<tr>
<td align="center">
<img src="img/007.png" />
</td>
<td align="center">
<img src="img/008.png" />
</td>
<td align="center">
<img src="img/009.png" />
</td>
<td align="center">
<img src="img/010.png" />
</td>
<td align="center">
<img src="img/011.png" />
</td>
</tr>
<tr>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
<td align="center">书名:xxx<br />价格:180</td>
</tr>
<tr>
<td colspan="5">
<img src="img/012.png" width="100%"/>
</td>
</tr>
</table>
</div>
</body>
</html>
学生信息管理系统案例
业务逻辑层
package com.qf.zonghe.Service.Impl;
import com.qf.zonghe.DAo.Impl.T_StuDaoImpl;
import com.qf.zonghe.Entity.T_Student;
import com.qf.zonghe.Util.DBUtil;
import java.util.List;
public class T_StuServerImpl {
private T_StuDaoImpl sd = new T_StuDaoImpl();
//学生信息添加功能
public String stuInsert(T_Student stu) {
int i = sd.insert(stu);
if (i > 0) {
return "添加成功";
} else {
return "添加失败";
}
}
//学生信息删除功能
public String stuDel(int id) {
int i = sd.delete(id);
if (i > 0) {
return "删除成功";
} else {
return "删除失败";
}
}
// 学生信息修改功能(除学号以外,其他均可修改)
public String stuUpdare(T_Student stu,int id){
T_Student stu2 = sd.seleect(id);
if(stu2 == null){
return "用户不存在";
}
int i = sd.update(stu,id);
if(i>0) {
return "修改成功";
}else{
return "修改失败";
}
}
// 学生登录功能
public String login(int id,String password){
if (sd.seleect(id) == null){
return "用户不存在";
}
if(sd.seleect(id).getPassword().equals(password)){
return "登陆成功";
}else{
return "密码错误";
}
}
// 学生信息查询功能单个学生
public String stuSelect(int id){
T_Student stu = sd.seleect(id);
if(stu != null){
return "查询到学生信息为" + stu.toString();
}else{
return "未查询到该学生信息";
}
}
// 学生信息查询功能所有学生
public List stuSelects(){
List<T_Student> stu = sd.selectAll();
if(stu == null){
return null;
}
return stu;
}
}
数据访问层
package com.qf.zonghe.DAo.Impl;
import com.qf.zonghe.DAo.dao;
import com.qf.zonghe.Entity.T_Student;
import com.qf.zonghe.Util.Daoutil;
import com.qf.zonghe.Util.DateUtil;
import com.qf.zonghe.adv.IMpl.StuMapperImpl;
import com.qf.zonghe.adv.StuMapper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
public class T_StuDaoImpl implements dao {
private Daoutil<T_Student> du = new Daoutil<T_Student>();
@Override
public int insert(T_Student stu) {
String sql = "insert into t_student(name,password,sex,borndate,phone) values(?,?,?,?,?)";
return du.commupdate(sql,stu.getName(), stu.getPassword(), stu.getSex(), stu.getBorndate(), stu.getPhone());
}
@Override
public int delete(int id) {
return du.commupdate("delete from t_student where id = ?", id);
}
@Override
public int update(T_Student stu,int id) {
String sql = "update t_student set name = ?,password=?,sex=?,borndate=?,phone = ? where id = ?";
return du.commupdate(sql,stu.getName(),stu.getPassword(),stu.getSex(),stu.getBorndate(),stu.getPhone(),id);
}
@Override
public T_Student seleect(int id) {
StuMapper<T_Student> sm = new StuMapperImpl();
List<T_Student> l = du.selects("select * from t_student where id = ?",sm,id);
if(l != null){
return l.get(0);
}
return null;
}
@Override
public List<T_Student> selectAll() {
StuMapper<T_Student> sm = new StuMapperImpl();
return du.selects("select * from t_student",sm);
}
}
接口回调函数
package com.qf.zonghe.adv.IMpl;
import com.qf.zonghe.Entity.T_Student;
import com.qf.zonghe.adv.StuMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
public class StuMapperImpl implements StuMapper<T_Student> {
@Override
public T_Student getRow(ResultSet re) {
T_Student stu = null;
try {
stu = new T_Student(re.getInt("id"),re.getString("name"),re.getString("password"),re.getString("sex"),re.getDate("borndate"),re.getString("phone"));
} catch (SQLException e) {
e.printStackTrace();
}
return stu;
}
}
DAO复用代码
package com.qf.zonghe.Util;
import com.qf.zonghe.Entity.T_Student;
import com.qf.zonghe.adv.StuMapper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class Daoutil<T> {
//公共DML方法
/**
* 公共处理增、删、改的方法
* sql语句,参数列表
*
* @param sql 执行的sql语句
* @param args 参数列表。为占位符赋值
* @return
*/
public int commupdate(String sql, Object... args) {
Connection conn = null;
PreparedStatement pre = null;
try {
conn = DBUtil.getConnection();
pre = conn.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
pre.setObject(i + 1, args[i]);
}
return pre.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(null, pre, null);
}
return 0;
}
/**
* 公共查询方法 (可查询单个对象,也可查询多个对象,可以查任何一张表)
*
* @param sql
* @param args
* @return
*/
public List<T> selects(String sql, StuMapper<T> sturow,Object... args){
Connection conn = null;
PreparedStatement pre = null;
ResultSet re = null;
List<T> list = new ArrayList<T>();
try {
conn = DBUtil.getConnection();
pre = conn.prepareStatement(sql);
if(args != null) {
for (int i = 0; i < args.length; i++) {
pre.setObject(i + 1, args[i]);
}
}
re = pre.executeQuery();
while(re.next()){
T t = sturow.getRow(re);
list.add(t);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
}
return list;
}
}
日期复用代码
package com.qf.zonghe.Util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class DateUtil {
private static final SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
//str转util.Date
public static java.util.Date strToUtil(String str){
try {
return sim.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
//util转换sql
public static java.sql.Date utilToSql(java.util.Date jud){
return new java.sql.Date(jud.getTime());
}
}
数据库连接复用代码
package com.qf.zonghe.Util;
import com.sun.xml.internal.ws.org.objectweb.asm.ClassAdapter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
public class DBUtil {
private static final Properties properties = new Properties();
private static final ThreadLocal<Connection> THREAD_LOCAL = new ThreadLocal<Connection>();
static {
InputStream is = DBUtil.class.getResourceAsStream("/db.properties");
try {
properties.load(is);
Class.forName(properties.getProperty("driver"));
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//获取连接
public static Connection getConnection(){
Connection conn = THREAD_LOCAL.get();
try {
if(conn == null){
conn = DriverManager.getConnection(properties.getProperty("url"),properties.getProperty("username"),properties.getProperty("password"));
THREAD_LOCAL.set(conn);
}
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
//开启事务
public static void begin(){
Connection conn = getConnection();
try {
conn.setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace();
}
}
//提交事务
public static void commit(){
Connection conn = getConnection();
try {
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(conn,null,null);
}
}
//回滚事务
public static void rollback(){
Connection conn = getConnection();
try {
conn.rollback();
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBUtil.close(conn,null,null);
}
}
//释放资源
public static void close(Connection conn, Statement st, ResultSet re){
try {
if(re != null){
re.close();
}
if(st != null){
st.close();
}
if(conn != null){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}