基于SSM框架流浪动物救助及领养管理系统(spring+springmvc+mybatis+jsp+jquery+layui)
这是一个基于SSM(Spring + Spring MVC + MyBatis)框架的流浪动物救助和领养管理系统的简化版本。以下是系统的核心部分代码示例:
applicationContext.xml(Spring配置)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 数据源配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db_pet"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
</bean>
<!-- MyBatis的SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<!-- 扫描Mapper接口的包路径 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.example.pet.mapper"/>
</bean>
<!-- 事务管理器配置, 使用DataSourceTransactionManager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
PetController.java(Spring MVC控制器)
package com.example.pet.controller;
import com.example.pet.entity.Pet;
import com.example.pet.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/pet")
public class PetController {
@Autowired
private PetService petService;
@GetMapping("/list")
public String list(Model model) {
model.addAttribute("pets", petService.findAll());
return "petList";
评论已关闭