SSM框架整合项目 :投票系统

Posted 谁将新樽辞旧月,今月曾经照古人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSM框架整合项目 :投票系统相关的知识,希望对你有一定的参考价值。

框架:

Spring

SpringMVC

MyBatis

题目:

投票系统

导包:

1, spring

2, MyBatis

3, mybatis-spring

4, fastjson

5, aspectweaver----AspectJ框架

6, log4j-----打印日志信息

7, ojdbc6.jar

8, jstl.jar, standard.jar----标准标签库

9, commons-logging-1.2.jar

10,……

建立包结构

配置web.xml,spring-mvc.xml,spring-all.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 3 
 4     <!-- 告诉web容器log4j的属性文件所在位置 -->
 5     <context-param>
 6         <param-name>log4jConfigLocation</param-name>
 7         <param-value>classpath:conf/log4j.properties</param-value>
 8     </context-param>
 9     <listener>
10         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
11     </listener>
12     
13     <!-- spring框架提供的字符编码过滤器 -->
14     <filter>
15         <filter-name>characterEncodingFilter</filter-name>
16         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
17         <init-param>
18             <param-name>encoding</param-name>
19             <param-value>UTF-8</param-value>
20         </init-param>
21         <init-param>
22             <param-name>forceEncoding</param-name>
23             <param-value>true</param-value>
24         </init-param>
25     </filter>
26     <filter-mapping>
27         <filter-name>characterEncodingFilter</filter-name>
28         <url-pattern>/*</url-pattern>
29     </filter-mapping>
30     
31     <!-- 加载spring配置文件 -->
32     <context-param>
33         <param-name>contextConfigLocation</param-name>
34         <param-value>classpath:conf/spring-config.xml</param-value>
35     </context-param>
36     <listener>
37         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
38     </listener>
39     
40     <!-- 加载springmvc配置文件 -->
41     <servlet>
42         <servlet-name>springDispatcherServlet</servlet-name>
43         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
44         <init-param>
45             <param-name>contextConfigLocation</param-name>
46             <param-value>classpath:conf/spring-mvc.xml</param-value>
47         </init-param>
48         <load-on-startup>1</load-on-startup>
49     </servlet>
50     <servlet-mapping>
51         <servlet-name>springDispatcherServlet</servlet-name>
52         <url-pattern>*.do</url-pattern>
53     </servlet-mapping>
54 </web-app>
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:mvc="http://www.springframework.org/schema/mvc"
 6     xmlns:p="http://www.springframework.org/schema/p"
 7     xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
 8         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
 9         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
10 
11 <!-- 引入数据库信息的属性文件 -->
12     <context:property-placeholder location="classpath:conf/db_orcl.properties" />
13     
14     <!-- 配置扫描器 -->
15     <context:component-scan base-package="com.hanqi.dao.impl" />
16     
17     <!-- 配置数据源 -->
18     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
19         <property name="username" value="${jdbc.username}"></property>
20         <property name="password" value="${jdbc.password}"></property>
21         <property name="driverClassName" value="${jdbc.driverClassName}"></property>
22         <property name="url" value="${jdbc.url}"></property>
23     </bean>
24     
25     <!-- 配置Mybatis核心对象 SessionFactory -->
26     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
27         <!-- mybatis中使用的别名 -->
28         <property name="typeAliasesPackage" value="com.hanqi.model"></property>
29         <!-- 注入数据源属性 -->
30         <property name="dataSource" ref="dataSource"></property>
31         <!-- Mybatis需要的映射文件 -->
32         <property name="mapperLocations" value="classpath:com/hanqi/dao/impl/*Mapper.xml"></property>
33     </bean>
34     
35     <!-- mybatis所有的映射接口 -->
36     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
37         <property name="basePackage" value="com.hanqi.dao"></property>
38         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
39     </bean>    
40 </beans>
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
 5     xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
 6         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 7         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
 8 
 9     <!-- 配置扫描器 -->
10     <context:component-scan base-package="com.hanqi.controller" />
11 
12     <!-- 配置视图解析器 -->
13     <bean
14         class="org.springframework.web.servlet.view.InternalResourceViewResolver"
15         p:prefix="/" p:suffix=".jsp"></bean>
16         
17     <!-- 开启mvc注解驱动 -->
18     <mvc:annotation-driven>
19         <!-- springMVC有一个默认的json格式的转换器, 是基于Jackson.jar, 但实际开发当中, fastjson -->
20         <mvc:message-converters register-defaults="false">
21             <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
22                 <!-- 配置支持的媒体类型 -->
23                 <property name="supportedMediaTypes">
24                     <list>
25                         <!-- 顺序不能写反, 否则会出现下载提示 -->
26                         <value>text/html; charset=utf-8</value>
27                         <value>application/json; charset=utf-8</value>
28                     </list>
29                 </property>
30             </bean>
31         </mvc:message-converters>
32     </mvc:annotation-driven>
33 </beans>

包结构文件:

model层---实体类:

 1 package com.hanqi.model;
 2 
 3 public class XiangMu {
 4     
 5     private String ids;
 6     private String title;
 7     private String selectiontype;
 8     private String isover;
 9 
10     public XiangMu(String ids, String title, String selectiontype, String isover) {
11         super();
12         this.ids = ids;
13         this.title = title;
14         this.selectiontype = selectiontype;
15         this.isover = isover;
16     }
17 
18     public XiangMu() {
19         super();
20         // TODO Auto-generated constructor stub
21     }
22 
23     public String getIds() {
24         return ids;
25     }
26 
27     public void setIds(String ids) {
28         this.ids = ids;
29     }
30 
31     public String getTitle() {
32         return title;
33     }
34 
35     public void setTitle(String title) {
36         this.title = title;
37     }
38 
39     public String getSelectiontype() {
40         return selectiontype;
41     }
42 
43     public void setSelectiontype(String selectiontype) {
44         this.selectiontype = selectiontype;
45     }
46 
47     public String getIsover() {
48         return isover;
49     }
50 
51     public void setIsover(String isover) {
52         this.isover = isover;
53     }
54 
55     @Override
56     public String toString() {
57         return "XiangMu [ids=" + ids + ", title=" + title + ", selectiontype=" + selectiontype + ", isover=" + isover
58                 + "]";
59     }
60 
61 }
 1 package com.hanqi.model;
 2 
 3 public class XuanXiang {
 4     
 5     private String ids;
 6     private String options;
 7     private Integer numbers;
 8     private String timudaihao;
 9     private String baifenb;
10 
11     public XuanXiang() {
12         super();
13         // TODO Auto-generated constructor stub
14     }
15 
16     public XuanXiang(String ids, String options, Integer numbers, String timudaihao) {
17         super();
18         this.ids = ids;
19         this.options = options;
20         this.numbers = numbers;
21         this.timudaihao = timudaihao;
22     }
23 
24     public String getBaifenb() {
25         return baifenb;
26     }
27 
28     public void setBaifenb(String baifenb) {
29         this.baifenb = baifenb;
30     }
31 
32     public String getIds() {
33         return ids;
34     }
35 
36     public void setIds(String ids) {
37         this.ids = ids;
38     }
39 
40     public String getOptions() {
41         return options;
42     }
43 
44     public void setOptions(String options) {
45         this.options = options;
46     }
47 
48     public Integer getNumbers() {
49         return numbers;
50     }
51 
52     public void setNumbers(Integer numbers) {
53         this.numbers = numbers;
54     }
55 
56     public String getTimudaihao() {
57         return timudaihao;
58     }
59 
60     public void setTimudaihao(String timudaihao) {
61         this.timudaihao = timudaihao;
62     }
63 
64     @Override
65     public String toString() {
66         return "XuanXiang [ids=" + ids + ", options=" + options + ", numbers=" + numbers + ", xiangmuid=" + timudaihao
67                 + "]";
68     }
69 
70 }

dao层---接口:

 1 package com.hanqi.dao;
 2 
 3 import java.util.List;
 4 
 5 import com.hanqi.model.XiangMu;
 6 import com.hanqi.model.XuanXiang;
 7 
 8 public interface TouPiaoDao {
 9 
10     List<XiangMu> selectAllXiangMu();
11     
12     List<XuanXiang> selectAllXuanXiang();
13 
14     int updatexuanxiang(String xuanxiang,int i);
15     
16     int selectXuanXiang(String xuanxiang);
17 }

dao层---实现方法:

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3   PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4   "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 <mapper namespace="com.hanqi.dao.TouPiaoDao">
 6     
 7     <select id="selectAllXiangMu" resultType="XiangMu">
 8         select t.* from DIAOYANTIMU  t where t.ids=101
 9     </select>
10     <select id="selectAllXuanXiang" resultType="XuanXiang" parameterType="String">
11         select t.* from DIAOYANXUANXIANG  t where t.timudaihao=101
12     </select>
13     <select id="selectXuanXiang" resultType="Integer">
14         select t.numbers from DIAOYANXUANXIANG  t where t.options=#{xuanxiang}
15     </select>
16     
17     <update id="updatexuanxiang">
18         update DIAOYANXUANXIANG t set t.numbers=#{param2} where t.options=#{param1}
19     </update>
20 
21 </mapper>

controller层---控制器:

 1 package com.hanqi.controller;
 2 
 3 import java.text.NumberFormat;
 4 import java.util.ArrayList;
 5 import java.util.List;
 6 
 7 import org.springframework.beans.factory.annotation.Autowired;
 8 import org.springframework.stereotype.Controller;
 9 import org.springframework.ui.Model;
10 import org.springframework.web.bind.annotation.RequestMapping;
11 import org.springframework.web.bind.annotation.ResponseBody;
12 import org.springframework.web.bind.annotation.SessionAttributes;
13 import org.springframework.web.servlet.ModelAndView;
14 
15 import com.alibaba.fastjson.JSONObject;
16 SSM框架整合项目 :租房管理系统

分布式电商项目(02)--后台管理系统SSM框架整合

IDEA+SSM+Maven实现商品管理系统(超详细SSM整合项目)

ssm框架整合(java个人博客系统)

SSM 项目整合详细解读

03 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目之web层