zoukankan      html  css  js  c++  java
  • 第一次迭代

    /ball/hnzj/controller/Chaxun.java
    package controller;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import domain.User;
    import service.ChaxunService;
    
    @Controller
    @RequestMapping("/chaxun")
    public class Chaxun {
        
        @Autowired
        private ChaxunService chaxunService;
        @RequestMapping("/chaxun")
        private String chaxun(User user){
        
            return "chaxun";        
        }
        
        @RequestMapping("/jieguo")
        public ModelAndView jieguo(User user){
        User user2 = chaxunService.getVs(user);
        
        ModelAndView mv =new ModelAndView();
        mv.setViewName("jieguo");
        mv.addObject("aa",user2);
            return mv;
            
            
        }
    }
    
    
    /ball/hnzj/dao/ChaxunDao.java
    package dao;
    
    import domain.User;
    
    public interface ChaxunDao {
        public User getVs(User user);
        public User getDefen(User user);
    }
    
    /ball/hnzj/domain/User.java
    package domain;
    
    public class User {
        private int id;
        private String vs;
        private String defen;
        private String huoshengfang;
        
        
        
        
        public String getDefen() {
            return defen;
        }
        public void setDefen(String defen) {
            this.defen = defen;
        }
        public String getHuoshengfang() {
            return huoshengfang;
        }
        public void setHuoshengfang(String huoshengfang) {
            this.huoshengfang = huoshengfang;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getVs() {
            return vs;
        }
        public void setVs(String vs) {
            this.vs = vs;
        }
        @Override
        public String toString() {
            return "User [id=" + id + ", vs=" + vs + ", defen=" + defen + ", huoshengfang=" + huoshengfang + "]";
        }
        
    }
    
    
    /ball/hnzj/service/ChaxunService.java
    package service;
    
    import domain.User;
    
    public interface ChaxunService {
        public User getVs(User user);
        public User getDefen(User user);
    }
    
    
    /ball/hnzj/service/Impl/ChaxunServiceImpl.java
    
    package service.Impl;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import dao.ChaxunDao;
    import domain.User;
    import service.ChaxunService;
    
    
    @Service
    public class ChaxunServiceImpl implements ChaxunService{
        
        @Autowired
        private ChaxunDao chaxunDao ;
    
        @Override
        public User getVs(User user) {
            return chaxunDao.getVs(user);
        }
    
        @Override
        public User getDefen(User user) {
            return chaxunDao.getDefen(user);
        }
        
    }
    
    
    /ball/config/mybatis/mapper/ChaxunDao.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "http://mybatis.org/dtd/mybatis-3-mapper.dtd" "mybatis-3-mapper.dtd" >
    <mapper  namespace="dao.ChaxunDao">
     
      <select id="getVs" parameterType="User" resultType="User" >     
          select * from ball where vs=#{vs};
        </select>
        <select id="getDefen" parameterType="User" resultType="User" >     
          select * from ball where defen=#{defen};
        </select>
    
    </mapper>
    
    
    
    
    /ball/config/mybatis/config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE configuration PUBLIC "http://mybatis.org/dtd/mybatis-3-config.dtd" "mybatis-3-config.dtd" >
    <configuration>
    
        <typeAliases>
            <typeAlias type="domain.User" alias="User"/>
        </typeAliases>
    </configuration>
    
    
    
    /ball/config/spring/applicationContext.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
        <context:annotation-config />
        <context:component-scan base-package="service"/>
        <!-- 加载数据库配置文件jdbc.properties -->
        <context:property-placeholder location="classpath:jdbc.properties"/>
        <!-- 配置数据库连接池,使用dbcp连接池 -->
        <bean  id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
            p:url="${jdbc.url}"
            p:username="${jdbc.username}"
            p:password="${jdbc.password}"
            p:driverClassName="${jdbc.driver}"
            p:maxActive="30"
            p:maxIdle="10"
            p:maxWait="1000"
            p:initialSize="15"/>
        <!-- 配置myBatis session工厂类,指定数据源,主配置文件,mapper映射文件,实体类所在包信息 -->
        <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
            p:dataSource-ref="dataSource"
            p:configLocation="classpath:mybatis/config.xml"
            p:mapperLocations="classpath:mybatis/mapper/**/*.xml"/>
        <!-- 指定dao接口所在位置,该类会根据接口和mapper配置文件信息自动创建接口的实现类,service层直接使用即可 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
            p:basePackage="dao"/>
        <!-- 配置事务管理器 -->
        <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
            p:dataSource-ref="dataSource"/>
        <aop:config>
            <aop:pointcut expression="execution(* hnzj.*.service.**.*(..))" id="serviceMethods"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
        </aop:config>
        <!-- 把事务管理器包装成advice -->
        <tx:advice id="txAdvice" transaction-manager="txManager">
            <tx:attributes>
                <tx:method name="save"  propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
    </beans>
    
    
    
    /ball/config/spring/spring-mvc.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
        <mvc:annotation-driven/>
        <!-- 扫描控制层 -->
        <context:component-scan base-package="controller" />
        <!-- 返回的逻辑视图匹配到实际视图 -->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:prefix="/WEB-INF/jsp/"
            p:suffix=".jsp"/>
        
    </beans>
    
    
    /ball/config/jdbc.properties
    jdbc.username=root
    jdbc.password=root
    jdbc.url=jdbc:mysql://localhost:3306/login?useUnicode=true&amp;characterEncoding=utf8
    jdbc.driver=com.mysql.jdbc.Driver
    
    
    /ball/WebContent/WEB-INF/jsp/chaxun.jsp
    <%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
        <style type="text/css">
        body, td
        {
          font-family: 宋体;
          font-size: 12px;
        }
        </style>
    <script language="javascript" src="hpmenu.js"></script>
    </head>
    <body>
        <form name="form1" method="post" action="/ball/chaxun/jieguo">
            <table width="90%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
              <tr bgcolor="F1F1F1">
                <td height="24" colspan="2" align="center">战队比拼查询表</td>
              </tr>
              <tr bgcolor="#FFFFFF">
                <td width="12%" height="24" align="center">所 在 洲:</td>
                <td><select name="vs" id="user"  >
                    <option value="" selected>-----请选择-----</option>
                        <option value='龙队vs虎队'>龙队vs虎队</option>
                        <option value='龙队vs豹队'>龙队vs豹队</option>
                        <option value='虎队vs豹队'>虎队vs豹队</option>
                        <option value='虎队vs龙队'>虎队vs龙队</option>
                        <option value='豹队vs龙队'>豹队vs龙队</option>
                        <option value='豹队vs虎队'>豹队vs虎队</option>
                </select></td>
              </tr>       
              <tr bgcolor="F1F1F1">
                <td height="24" colspan="2" align="center"> </td>
              </tr>
       </table>
         <br>
            <input type="submit" value="查询" >
    </form>
    </body>
    </html>
    
    
    /ball/WebContent/WEB-INF/jsp/jieguo.jsp
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    ${aa.vs} <br>比分 ${aa.defen}<br> 获胜方 ${aa.huoshengfang}<br>
    
    <a href="javascript :;" onClick="javascript :history.back(-1);">返回 </a>
    
    </body>
    </html>
    
    /ball/WebContent/WEB-INF/web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
      <display-name>ball</display-name>
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/applicationContext.xml</param-value>
      </context-param>
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      <filter>
        <filter-name>characterFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>utf-8</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>characterFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <servlet>
        <servlet-name>ball</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:spring/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>ball</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

    最近要开一个项目《考试系统》

    用到ssm框架

    Spring MVA       Spring       MyBatis

    刚把框架学着搭好,老师就要求第一次迭代,学以致用,我便用ssm做了这个迭代。

    在迭代的过程中 出现好多自己不理解的,多亏我们组长龚鹏飞和青鸟班王顺利。还有陈老师,我简直不能想想,昨天我还不理解需求书!!!

    代码较多,各个层,我也是昨天才搞明白。对不起我忘记加注释了大家看不懂也正常,(好的编码习惯还是要养成的)

    虽然一个很小的功能,但麻雀虽小,五脏俱全。

    还有里面有些jar包,大家若想运行的话  请联系我  我把jar包给你们

    访问页面地址:http://localhost:8080/ball/chaxun/chaxun

  • 相关阅读:
    bzoj1861 [Zjoi2006]Book 书架
    bzoj1208 [HNOI2004]宠物收养所
    bzoj1588 [HNOI2002]营业额统计
    bzoj3295 [Cqoi2011]动态逆序对
    bzoj2716 [Violet 3]天使玩偶
    bzoj1176 [Balkan2007]Mokia
    bzoj3262 陌上花开
    spoj FTOUR2
    bzoj2152 聪聪可可
    poj1741 Tree
  • 原文地址:https://www.cnblogs.com/CCTV-1/p/6211863.html
Copyright © 2011-2022 走看看