该项目是一个基于JavaWeb、MySQL、Spring Boot、Vue和Element UI的地废物收集处理机构的管理系统。
由于项目较大且涉及多个文件,以下仅提供核心依赖和配置文件的代码示例。
pom.xml(依赖管理)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 其他依赖省略 -->
</dependencies>
application.properties(数据库配置)
spring.datasource.url=jdbc:mysql://localhost:3306/garbage_collection_establishment?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=yourpassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.yourpackage.model
Java配置类(Spring Boot配置)
@Configuration
public class MyBatisConfig {
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
return sqlSessionFactoryBean.getObject();
}
@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
Service层示例代码
@Service
public class EstablishmentService {
@Autowired
private EstablishmentMapper establishmentMapper;
public Establishment getEstablishmentById(Integer id) {
return establishmentMapper.selectByPrimaryKey(id);
}
// 其他方法省略
}
Mapper XML示例
<mapper namespace="com.yourpackage.mapper.EstablishmentMapper">
<resultMap id="BaseResultMap" type="com.yourpackage.model.Establishment">
<id column="id" property="id" />
<result column="name" property="name" />
<!-- 其他字段映射省略 -->
</resultMap>
<select id="selectByPrimaryKey" re