项目介绍
本系统使用Spring+SpringMVC+MyBatis架构,数据库使用MySQL,前端页面使用jsp设计的道路管理系统,主要有道路分类管理,添加道路管理,巡查记录管理,评价管理等模块。
开发环境
- jdk 8
- intellij idea
- tomcat 8.5.40
- mysql 5.7
所用技术
- Spring+SpringMVC+MyBatis
- layui
- jsp
项目截图
-
分类管理
-
添加道路
-
添加评价
-
巡查记录
-
系统介绍
框架配置
- db.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost/urbanRoad?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.username=root
jdbc.password=root123
- applicationContext-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:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
<context:component-scan base-package="com.lrfalse.controller"/>
<mvc:interceptors>
<mvc:interceptor>
<!-- 需要拦截的url路径 :/order/** 这个是订单系统的url格式 -->
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/login"/>
<mvc:exclude-mapping path="/*.js"/>
<mvc:exclude-mapping path="/register"/>
<mvc:exclude-mapping path="/logout"/>
<bean class="com.lrfalse.interceptor.LoginInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- 支持aop的注解 -->
<aop:aspectj-autoproxy/>
<!-- 启动SpringMVC的注解功能 -->
<mvc:annotation-driven/>
<!--静态资源放行-->
<mvc:default-servlet-handler/>
<!-- 定义跳转的文件的前后缀 ,视图解析器配置-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 配置文件上传解析器 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 默认编码 -->
<property name="defaultEncoding" value="utf-8"/>
<!-- 文件大小最大值 -->
<property name="maxUploadSize" value="10485760000"/>
</bean>
</beans>
- applicationContext-service.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath*:applicationContext-mapper.xml"/>
<!--扫描的包-->
<context:component-scan base-package="com.lrfalse.service"/>
</beans>
- applicationContext-mapper.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Jdbc配置文件 -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 数据源dataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!--maxActive: 最大连接数量 -->
<property name="maxActive" value="150" />
<!--minIdle: 最小空闲连接 -->
<property name="minIdle" value="5" />
<!--maxIdle: 最大空闲连接 -->
<property name="maxIdle" value="20" />
<!--initialSize: 初始化连接 -->
<property name="initialSize" value="30" />
<!--maxWait: 超时等待时间以毫秒为单位 1000等于60秒 -->
<property name="maxWait" value="1000" />
<!-- 在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位. -->
<property name="timeBetweenEvictionRunsMillis" value="10000" />
<!-- 在每次空闲连接回收器线程(如果有)运行时检查的连接数量 -->
<property name="numTestsPerEvictionRun" value="10" />
<!-- 1000 * 60 * 30 连接在池中保持空闲而不被空闲连接回收器线程 -->
<property name="minEvictableIdleTimeMillis" value="10000" />
<property name="validationQuery" value="SELECT NOW() FROM DUAL" />
</bean>
<!--Mybatis核心对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置mybatis (mapper)映射器路径 -->
<property name="mapperLocations" value="classpath*:mapper/*Mapper.xml" />
<!--引用mybatis的核心配置文件-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- 配置mybatis 类型别名 -->
<property name="typeAliasesPackage">
<value>
com.lrfalse.entity
com.lrfalse.query
</value>
</property>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
reasonable=true
</value>
</property>
</bean>
</array>
</property>
</bean>
<!--注入映射器,一劳永逸的做法-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.lrfalse.mapper"></property>
</bean>
<!--事务管理-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--以注解的方式进行事务管理-->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
业务代码
- 道路信息保存
@RequestMapping("/save")
@ResponseBody
public AjaxResult save(RoadReq roadReq){
try {
Road road=new Road(); //主道路信息
BeanUtil.copyProperties(roadReq,road);
Roadway roadway=new Roadway();
BeanUtil.copyProperties(roadReq,roadway);//车行道对象
roadway.setId(roadReq.getRoadwayId());
Separator separator=new Separator();
BeanUtil.copyProperties(roadReq,separator);//分隔带
separator.setId(roadReq.getSeparatorId());
Sidewalk sidewalk=new Sidewalk();
BeanUtil.copyProperties(roadReq,sidewalk);//人行道
sidewalk.setId(roadReq.getSidewalkId());
AncillaryFacilities ancillaryFacilities=new AncillaryFacilities();
BeanUtil.copyProperties(roadReq,ancillaryFacilities);//附属设施对象
ancillaryFacilities.setId(roadReq.getAncillaryFacilitiesId());
if(road.getId()!=null){
roadService.update(road);
iAncillaryFacilitiesService.update(ancillaryFacilities);
iRoadwayService.update(roadway);
iSeparatorService.update(separator);
iSidewalkService.update(sidewalk);
return new AjaxResult("修改成功!");
}else{
roadService.add(road);
iAncillaryFacilitiesService.add(ancillaryFacilities);
iRoadwayService.add(roadway);
iSeparatorService.add(separator);
iSidewalkService.add(sidewalk);
return new AjaxResult("保存成功!");
}
} catch (Exception e) {
e.printStackTrace();
return new AjaxResult("保存失败:"+e.getMessage(),-10002);
}
}
//前端jsp代码
<div class="layui-row" id="zq_formpopbox" style="position: absolute;
top: 0; left: 0; bottom: 0; right: 0;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;color: #007DDB">
<legend>街道基础信息</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="">
<div class="layui-col-md3">
<div class="layui-form-item">
<label class="layui-form-label">道路名称</label>
<div class="layui-input-block">
<input type="text" name="roadName" id="roadName" lay-verify="required" placeholder="请输入道路名称"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">道路编号</label>
<div class="layui-input-block">
<input type="text" name="roadNum" id="roadNum" lay-verify="required" placeholder="请输入道路编号"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">道路走向</label>
<div class="layui-input-block">
<input type="text" name="roadTo" id="roadTo" lay-verify="required" placeholder="请输入道路走向"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">起点</label>
<div class="layui-input-block">
<input type="text" name="origin" id="origin" lay-verify="required" placeholder="请输入起点"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">终点</label>
<div class="layui-input-block">
<input type="text" name="destination" id="destination" lay-verify="required" placeholder="请输入终点"
autocomplete="off" class="layui-input">
</div>
</div>
</div>
<div class="layui-col-md3">
<div class="layui-form-item">
<label class="layui-form-label">设计单位</label>
<div class="layui-input-block">
<input type="text" name="architect" id="architect" lay-verify="required" placeholder="请输入设计单位"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">施工单位</label>
<div class="layui-input-block">
<input type="text" name="constructionOrganization" id="constructionOrganization"
lay-verify="required" placeholder="请输入施工单位" autocomplete="off" class="lay