JAVA-based online voting system under the framework of SSM

Record learning every day, have a good mood every day. * ^ _ ^ *

When learning online voting system project, to facilitate future access to timely, record it in this platform in the development process of the project. In the study, when the selection of the SSM (MYECLIPSE), whether this framework is to learn or use are very convenient, simple and approachable. Is a framework that we can focus on learning to learn programming, I chose MYECLIPSE in the development of online voting system when the project to build SSM (MYECLIPSE) framework, will eventually online voting systems project development background to a project.
The project has included the Administrator user role, user, each role contains its own user name and password.

The summary results of all system data: administrator (admin), voting (toupiao), user (yonghu)

Administrators table

Field Name | Type | property | describe 
the above mentioned id |  INT ( 11 ) |  PRIMARY  KEY  | administrator the above mentioned id 
username |  VARCHAR ( 255 ) |  | account 
password |  VARCHAR ( 255 ) |  | password

 


 

Voting table

Field Name | Type | property | describe 
the above mentioned id |  INT ( 11 ) |  PRIMARY  KEY  | vote the above mentioned id 
biaoti |  VARCHAR ( 255 ) |  | title 
neirong |  VARCHAR ( 255 ) |  | Content 
xuanxianga |  VARCHAR ( 255 ) |  | Option A 
xuanxiangb |  VARCHAR ( 255 ) |  |Option B 
xuanxiangc |  VARCHAR ( 255 ) |  | option C 
xuanxiangd |  VARCHAR ( 255 ) |  | option D 
xuanxiangacs |  VARCHAR ( 255 ) |  | Option A number 
xuanxiangbcs |  VARCHAR ( 255 ) |  | option number B 
xuanxiangccs |  VARCHAR ( 255 ) |  | option number C 
xuanxiangdcs |  VARCHAR (255 ) |  | option number D

 

user table

Field Name | Type | property | describe 
the above mentioned id |  INT ( 11 ) |  PRIMARY  KEY  | user the above mentioned id 
nicheng |  VARCHAR ( 255 ) |  | nickname 
username |  VARCHAR ( 255 ) |  | account 
password |  VARCHAR ( 255 ) |  | password

 

 

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------

-- ----------------------------

-- Table structure for ggtoupiaoxitong

-- ----------------------------

DROP TABLE IF EXISTS `t_admin`;

CREATE TABLE `t_admin` (`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '管理员id',`username` VARCHAR(255) DEFAULT NULL COMMENT '账号',`password` VARCHAR(255) DEFAULT NULL COMMENT '密码',PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='管理员';

-- ----------------------------

DROP TABLE IF EXISTS `t_toupiao`;

CREATE TABLE `t_toupiao` (`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '投票id' , `Biaoti` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' title ' ,` neirong` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' content ' , `xuanxianga` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' option A ' ,` xuanxiangb` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' option B ' , `xuanxiangc` VARCHAR (255 ) the DEFAULT  NULL the COMMENT ' option C ' , `xuanxiangd` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' option D ' ,` xuanxiangacs` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' Option A number ' , `xuanxiangbcs` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' option number B ' , `xuanxiangccs` VARCHAR ( 255 ) the DEFAULT  NULLThe COMMENT ' option number C ' , `xuanxiangdcs` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' option number D ' , a PRIMARY  KEY (` id`) 

) ENGINE = MyISAM the DEFAULT the CHARSET = UTF8 the COMMENT = ' vote ' ; 

- ---- ------------------------ 

the DROP  TABLE  the IF  EXISTS `t_yonghu`; 

the CREATE  TABLE ` t_yonghu` ( `id` the INT ( . 11 ) the NOT  NULLThe COMMENT the AUTO_INCREMENT ' user ID ' , `nicheng` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' nickname ' ,` username` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' account number ' , `password` VARCHAR ( 255 ) the DEFAULT  NULL the COMMENT ' password ' , a PRIMARY  KEY ( `id`) 

) ENGINE = MyISAM the DEFAULT the CHARSET =the COMMENT UTF8 = ' user ' ;

 

 

Add voting module:

By adding voting module can be added to complete the operation to vote. Jump all the information on the page to add voting page, enter the vote, click Add to operate, can be submitted to the voting data to post in toupiaoController. Field contains information includes polls title, content, Option A, Option B, option C, D options, Option A number, B number of options, the number of option C, the number of options D. In toupiaoController in toupiao accept all votes by defining parameters. Using the insert method toupiaodao toupiao entities into the database. The process of adding data corresponding to the matching toupiaoxml complete the insertion operation is performed in the sql statement in toupiaoMapper. The part of the core code is as follows:

The voting method by adding toupiaodao insert page transmitted to the database toupiaodao.insert (toupiao);

Add the successful vote information is saved to the message request, the user is given prompt request.setAttribute in the page ( "message", "Add vote successfully");

Voting returns management interface

return "forward:/tianjiatoupiao.action";

Query voting module:

When the inquiry into the voting page in a browser, then the browser address bar is toupiaoguanli.action, the address will respond toupiaoController class toupiaoguanli, in the process, get all the information selectByexample voting method, and the information save the request, make cycle through the pages. The portion of the core code is as follows:

Generating a sample voting class, query by example defined ToupiaoExample example = new ToupiaoExample ();

Check out all the voting information List toupiaoall = toupiaodao.selectByExample (example) by selectByExample method of toupiaodao;

The voting information stored in the request, on display request.setAttribute ( "toupiaoall", toupiaoall) page by foreach method;

Voting returns management interface

return "forward:/toupiaoguanli.action";

Modify voting module:

After filling out the page modify information, click the Modify button to submit data to xiugaitoupiao, the package is a vote

Used to modify the vote information update method, the data is synchronized to the database, to complete the modification operation.

Modify the definition of a successful message, modify the vote is successful, and save it to request specific code is as follows:

Modified corresponding voting toupiaodao.updateByPrimaryKeySelective (toupiao) by modifying the method according to the id of toupiaodao;

The vote successfully modify information stored in the message request, give the user prompt request.setAttribute in the page ( "message", "modify voting information successfully");

Voting returns management interface

return "forward:/toupiaoguanli.action";

Delete voting module:

Voting delete function is implemented in toupiaoController, the implementation is shanchutoupiao. shanchutoupiao.action the page by the get method? Id form will be deleted id vote uploaded to the server in response to a corresponding method, call deleteByPrimaryKey method toupiaodao in complete deletion. Will delete successful message is returned to the page, complete the operation to delete data. The part of the core code:

Deletes the corresponding voting toupiaodao.deleteByPrimaryKey (id) id by removing method according to the toupiaodao;

Successful vote will delete information stored in the message request, give the user prompt request.setAttribute in the page ( "message", "delete vote successfully");

Voting returns management interface

return "forward:/toupiaoguanli.action";

Guess you like

Origin www.cnblogs.com/lsjyy/p/11587221.html