最近从一个群里下载了一个“都市信息供求网”的源码,struts2+msql的。逐步测一下,以便学习。
直接运行源码中的mysql脚本不行,中文部分输入不全。把sql脚本分成了几段,删除了一些版本信息,存成文本文件,可以了。
CREATE DATABASE IF NOT EXISTS `db_cityinfo` DEFAULT CHARACTER SET utf8 ;
USE `db_cityinfo`;
/*Table structure for table `tb_info` */
DROP TABLE IF EXISTS `tb_info`;
CREATE TABLE `tb_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`info_type` int(11) DEFAULT NULL,
`info_title` varchar(80) DEFAULT NULL,
`info_content` varchar(1000) DEFAULT NULL,
`info_linkman` varchar(50) DEFAULT NULL,
`info_phone` varchar(50) DEFAULT NULL,
`info_email` varchar(100) DEFAULT NULL,
`info_date` datetime DEFAULT NULL,
`info_state` varchar(1) DEFAULT NULL,
`info_payfor` varchar(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;
/*Data for the table `tb_info` */
insert into `tb_info`(`id`,`info_type`,`info_title`,`info_content`,`info_linkman`,`info_phone`,`info_email`,`info_date`,`info_state`,`info_payfor`) values (1,1,'招聘信息标题','招聘信息标题','明明','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(2,2,'培训信息标题','培训信息标题','明明','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(3,3,'房屋信息标题','房屋信息标题','明明','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(4,4,'求购信息标题','求购信息标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(5,5,'招商引资标题','招商引资标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(6,6,'公寓信息标题','公寓信息标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(7,7,'求职信息标题','求职信息标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(8,8,'家教信息标题','家教信息标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(9,9,'车辆信息标题','车辆信息标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(10,10,'出售信息标题','出售信息标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(11,11,'寻找启示标题','寻找启示标题','芳芳','13255******','888@8*.com','2013-05-05 00:00:00','1','1'),(12,1,'发布培训信息标题','发布培训信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(13,2,'发布屋信息标题','发布屋信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(14,3,'发布求购信息标题','发布求购信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(15,4,'发布招商引资标题','发布招商引资标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(16,5,'发布公寓信息标题','发布公寓信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(17,6,'发布求职信息标题','发布求职信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(18,7,'发布家教信息标题','发布家教信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(19,8,'发布车辆信息标题','发布车辆信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(20,9,'发布出售信息标题','发布出售信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(21,10,'发布寻找启示标题','发布寻找启示标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0'),(22,11,'发布招聘信息标题','发布招聘信息标题','小免','111111******','44@1*.com','2013-05-05 00:00:00','1','0');
/*Table structure for table `tb_type` */
DROP TABLE IF EXISTS `tb_type`;
CREATE TABLE `tb_type` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type_sign` int(11) DEFAULT NULL,
`type_name` varchar(20) DEFAULT NULL,
`type_intro` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
/*Data for the table `tb_type` */
insert into `tb_type`(`id`,`type_sign`,`type_name`,`type_intro`) values (1,1,'recruit','招聘信息'),(2,2,'training','培训信息'),(3,3,'house','房屋信息'),(4,4,'buy','求购信息'),(5,5,'invite','招商引资'),(6,6,'apartment','公寓信息'),(7,7,'apply','求职信息'),(8,8,'tutor','家教信息'),(9,9,'car','车辆信息'),(10,10,'sale','出售信息'),(11,11,'search','寻找启示');
/*Table structure for table `tb_user` */
DROP TABLE IF EXISTS `tb_user`;
CREATE TABLE `tb_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) DEFAULT NULL,
`user_password` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*Data for the table `tb_user` */
insert into `tb_user`(`id`,`user_name`,`user_password`) values (1,'tsoft','111'),(2,'yxq','000'),(3,'admin','222');
为了测部分代码,把struts.xml修改了一下:
<struts>
<package name="cityInfo" namespace="/" extends="struts-default">
<!-- 访问首页 -->
<action name="goindex" class="com.yxq.action.IndexAction">
<result name="index">/view/IndexTemp.jsp</result>
</action>
</package>
</struts>
package com.yxq.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import com.yxq.model.CreatePage;
import com.yxq.model.InfoSingle;
import com.yxq.tools.DoString;
public class test_OpDB {
private DB mydb;
public test_OpDB(){
mydb=new DB();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public List OpListShow(String sql,Object[] params){
List onelist=new ArrayList();
String temp="";
mydb.doPstm(sql, params);
try{
ResultSet rs=mydb.getRs();
if(rs!=null){
while(rs.next()){
System.out.println(rs.getInt("id"));
System.out.println(rs.getInt("info_type"));
temp=rs.getString("info_title");
temp=new String(temp.getBytes("iso-8859-1"),"gb2312");
System.out.println(temp);
System.out.println(rs.getTimestamp("info_date"));
}
}
rs.close();
}catch (Exception e){
System.out.println("查看信息列表失败!(查询数据库)");
e.printStackTrace();
}finally{
mydb.closed();
}
return onelist;
}
}
最后运行下面程序
package com.yxq.action;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import com.yxq.actionSuper.MySuperAction;
import com.yxq.dao.OpDB;
import com.yxq.dao.test_OpDB;
public class test_IndexAction extends MySuperAction{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String sql1="select * from tb_info where (info_state='1') and (info_payfor = '1') order by info_date desc";
test_OpDB myOp=new test_OpDB();
List payforlist=myOp.OpListShow(sql1,null);
}
}
源代码代码:http://pan.baidu.com/share/link?shareid=439464&uk=3878681452