springmvc项目创建

一、项目创建

建web项目
web项目结构

二、设置字节码文件class生成路径

加config文件夹

默认class生成路径

选路径

定义class生成路径

这里写图片描述

这里写图片描述

三、设置编码

css设置utf-8

html设置utf-8

jsp设置utf-8

四、导包

所有包

lib目录放入包

五、配置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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

  <!-- 通过监听器初始配置文件 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext_a_dataSource.xml,classpath:applicationContext_c_transaction.xml,classpath:applicationContext_d_mybatis.xml</param-value>
  </context-param>
  <!-- 监听contextConfigLocation的配置文件 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  <!-- 分发器,初始springmvc配置文件 -->
  <servlet>
    <servlet-name>springDispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext_e_springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springDispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <!-- restful风格,form提交隐藏域使用 -->
  <filter>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- 默认跳转页面 -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

六、配置springmvc配置文件

applicationContext_e_springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
">

    <!-- 自动扫描 -->
    <context:component-scan base-package="com.finance">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
    </context:component-scan>

    <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

七、配置其他配置文件

applicationContext_a_dataSource.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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xsi:schemaLocation="  
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd  
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
     ">
    <!-- 引入属性文件 -->
    <context:property-placeholder location="classpath:config.properties" />
    <!-- 开发配置-->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${driverClassName}" />
        <property name="url" value="${url}" />
        <property name="username" value="${userName}" />
        <property name="password" value="${password}" />
    </bean>
</beans>

applicationContext_c_transaction.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2010 The myBatis Team Licensed under the Apache License, Version 
    2.0 (the "License"); you may not use this file except in compliance with 
    the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
    Unless required by applicable law or agreed to in writing, software distributed 
    under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
    OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
    the specific language governing permissions and limitations under the License. -->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">

    <context:component-scan base-package="com.finance">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!-- transaction manager, use JtaTransactionManager for global tx -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- enable transaction demarcation with annotations -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

    <!-- 缺省的异步任务线程池 -->
    <task:annotation-driven executor="asyncExecutor" />
    <task:executor id="asyncExecutor" pool-size="100-10000" queue-capacity="10" />
</beans>

applicationContext_d_mybatis.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:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <!-- define the SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 配置文件 -->
        <property name="configLocation" value="classpath:mybatis-config.xml" />
        <!-- <property name="typeAliasesPackage" value="com.edais.domain,com.lb.sssq.domain" 
            /> -->
        <!-- <property name="typeAliasesPackage" value="com.lincomb.admin.base.login.domain" 
            /> -->
        <property name="typeAliasesPackage"
            value="
        com.finance.manager.agreement.models
        " />
        <!-- <property name="mapperLocations"> <list> com.lincomb.manager.system.mapper.*.xml 
            </list> </property> -->
    </bean>

    <!-- scan for mappers and let them be autowired -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- <property name="basePackage" value="com.edais.persistence,com.lb.sssq.persistence" 
            /> -->
        <!-- <property name="basePackage" value="com.lincomb.admin.base.login.persistence" 
            /> -->
        <property name="basePackage"
            value="
        com.finance.manager.agreement.mapper
        " />
    </bean>
</beans>

mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd" >  
<configuration>  
    <settings>  
        <!-- 全局映射器启用缓存 -->  
        <setting name="cacheEnabled" value="false" />  
        <!-- 查询时,关闭关联对象即时加载以提高性能 -->  
        <setting name="lazyLoadingEnabled" value="false" />  
        <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->  
        <setting name="aggressiveLazyLoading" value="false" />  
        <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->  
        <setting name="multipleResultSetsEnabled" value="true" />  
        <!-- 允许使用列标签代替列名 -->  
        <setting name="useColumnLabel" value="true" />  
        <!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->  
        <setting name="useGeneratedKeys" value="true" />  
        <!-- 给予被嵌套的resultMap以字段-属性的映射支持 -->  
        <setting name="autoMappingBehavior" value="FULL" />  
        <!-- 对于批量更新操作缓存SQL以提高性能 -->  
        <setting name="defaultExecutorType" value="SIMPLE" />  
        <!-- 数据库超过25000秒仍未响应则超时 -->  
        <setting name="defaultStatementTimeout" value="25000" />
         <!-- 输出日志 -->
        <setting name="logImpl" value="LOG4J"/>
        <!-- 空值输出 -->
        <setting name="callSettersOnNulls" value="true"/>  
    </settings>
</configuration>   

config.properties

#dev
driverClassName = oracle.jdbc.driver.OracleDriver
url = jdbc:oracle:thin:@XXX.XXX.XXX.XX:51521/XXXXXX
userName = XXXXXX
password = XXXXXX
maxActive = 40
maxIdle   = 5
defaultAutoCommit             = false
timeBetweenEvictionRunsMillis = 3600000
minEvictableIdleTimeMillis    = 3600000

interfacePath = http://127.0.0.1:8080/javaservice

八、代码

AgreementTemplateMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.finance.manager.agreement.mapper.AgreementTemplateMapper">
    <resultMap id="BaseResultMap" type="com.finance.manager.agreement.models.AgreementTemplate">
      <id column="ID" jdbcType="VARCHAR" property="id" />
      <result column="AGREEMENT_NO" jdbcType="VARCHAR" property="agreementNo" />
      <result column="AGREEMENT_NAME" jdbcType="VARCHAR" property="agreementName" />
      <result column="AGREEMENT_CONTENT" jdbcType="VARCHAR" property="agreementContent" />
      <result column="AGREEMENT_PRINTCONTENT" jdbcType="VARCHAR" property="agreementPrintcontent" />
      <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
      <result column="IS_ENABLED" jdbcType="VARCHAR" property="isEnabled" />
      <result column="SAVEPATH" jdbcType="VARCHAR" property="savepath" />
    </resultMap>
    <sql id="Base_Column_List">
        ID, AGREEMENT_NO, AGREEMENT_NAME, AGREEMENT_CONTENT, AGREEMENT_PRINTCONTENT, 
        UPDATE_TIME, IS_ENABLED, SAVEPATH
    </sql>

    <!-- 查询合同模板列表  -->
    <select id="queryAgreementTemplateList" resultMap="BaseResultMap">
        select 
        <include refid="Base_Column_List" />
        from base_agreement_template
    </select>

</mapper>

AgreementTemplateController.java

package com.finance.manager.agreement.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.finance.manager.agreement.models.AgreementTemplate;
import com.finance.manager.agreement.service.AgreementTemplateService;


@Controller
@RequestMapping(value="/agreement")
public class AgreementTemplateController {

    @Autowired
    private AgreementTemplateService agreementTemplateService;

    /**
     * http://localhost:8080/finance/agreement/agreementTemplateList
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/agreementTemplateList")
    public String list(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        List<AgreementTemplate> agreementTemplateList = agreementTemplateService.queryAgreementTemplateList();
        modelMap.put("agreementTemplateList", agreementTemplateList);
        return "/agreement/agreementTemplateList";
    }
}

AgreementTemplateMapper.java

package com.finance.manager.agreement.mapper;

import java.util.List;

import com.finance.manager.agreement.models.AgreementTemplate;

public interface AgreementTemplateMapper {

    List<AgreementTemplate> queryAgreementTemplateList();
}

AgreementTemplate.java

package com.finance.manager.agreement.models;

import java.util.Date;

public class AgreementTemplate {

    private String id;

    private String agreementNo;

    private String agreementName;

    private String agreementContent;

    private String agreementPrintcontent;

    private Date updateTime;

    private String isEnabled;

    private String savepath;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getAgreementNo() {
        return agreementNo;
    }

    public void setAgreementNo(String agreementNo) {
        this.agreementNo = agreementNo;
    }

    public String getAgreementName() {
        return agreementName;
    }

    public void setAgreementName(String agreementName) {
        this.agreementName = agreementName;
    }

    public String getAgreementContent() {
        return agreementContent;
    }

    public void setAgreementContent(String agreementContent) {
        this.agreementContent = agreementContent;
    }

    public String getAgreementPrintcontent() {
        return agreementPrintcontent;
    }

    public void setAgreementPrintcontent(String agreementPrintcontent) {
        this.agreementPrintcontent = agreementPrintcontent;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getIsEnabled() {
        return isEnabled;
    }

    public void setIsEnabled(String isEnabled) {
        this.isEnabled = isEnabled;
    }

    public String getSavepath() {
        return savepath;
    }

    public void setSavepath(String savepath) {
        this.savepath = savepath;
    }
}

AgreementTemplateServiceImpl.java

package com.finance.manager.agreement.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.finance.manager.agreement.mapper.AgreementTemplateMapper;
import com.finance.manager.agreement.models.AgreementTemplate;
import com.finance.manager.agreement.service.AgreementTemplateService;


@Service
public class AgreementTemplateServiceImpl implements AgreementTemplateService {

    @Autowired
    private AgreementTemplateMapper agreementTemplateMapper;

    @Override
    public List<AgreementTemplate> queryAgreementTemplateList() {
        return agreementTemplateMapper.queryAgreementTemplateList();
    }
}

AgreementTemplateService.java

package com.finance.manager.agreement.service;

import java.util.List;

import com.finance.manager.agreement.models.AgreementTemplate;


public interface AgreementTemplateService {

    List<AgreementTemplate> queryAgreementTemplateList();

}

agreementTemplateList.jsp

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title></title>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <div>
            <div>
                <table border="1" cellpadding="10" cellspacing="0">
                    <thead>
                        <tr>
                            <th>合同模板编号</th>
                            <th>合同模板名称</th>
                            <th>是否启用</th>
                            <th>修改时间</th>
                        </tr>
                    </thead>
                    <c:if test="${empty agreementTemplateList}">
                        <tr>
                            <td style="text-align:center;"><font style="font-size:15px;">查询无数据</font></td>
                        </tr>
                    </c:if>
                    <c:forEach items="${agreementTemplateList}" var="agreementTemplate">
                        <tr>
                            <input type="hidden" name="agreementNo" value="${agreementTemplate.agreementNo}"/>
                            <td style="text-align:center;">${agreementTemplate.agreementNo}</td>
                            <td style="text-align:center;">${agreementTemplate.agreementName}</td>
                            <td style="text-align:center;"><c:if test="${agreementTemplate.isEnabled eq '1'}"></c:if><c:if test="${agreementTemplate.isEnabled eq '0'}"></c:if></td>
                            <td style="text-align:center;"><fmt:formatDate value="${agreementTemplate.updateTime}" pattern="yyyy-MM-dd  HH:mm:ss"/></td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
        </div>
    </body>
</html>

九、项目结构

项目结构

十、运行结果

web项目设置
http://localhost:8080/finance/agreement/agreementTemplateList

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值