[SSM Complete Small Project] Event Recording System

I have been busy with postgraduate review planning recently, and I haven’t written a blog for a long time. Today, I released the two small SSM projects (implementing basic additions, deletions, revisions, and project structure deployment) that I did at the end of the semester for everyone to exchange and share.

Project address: https://github.com/gaoliwei1102/Event-Notes

project structure directory

insert image description here

insert image description here

Screenshot of the main running of the project

The main page of the project

insert image description here

Information List Page (Event List)

insert image description here

Add big event page

insert image description here

Modify the big event page

insert image description here

To delete an event, simply click the delete button.

The main configuration file for the project

spring-dao database persistence layer configuration file

<?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
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">

    <!--1、关联数据库文件-->
    <context:property-placeholder location="classpath:database.properties"/>
    <!--2、连接池-->
    <!--
    C3p0:自动化操作(自动化的加载配置文件,并且可以自动设置到对象中)
    jdbc:半自动化操作,不能自动连接
    druid:
    hikari:
    -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${driver}"/>
        <property name="jdbcUrl" value="${url}"/>
        <property name="user" value="${user}"/>
        <property name="password" value="${password}"/>

        <!--c3p0的私有属性-->
        <property name="maxPoolSize" value="30"/>
        <property name="minPoolSize" value="10"/>
        <!--关闭连接后不能自动连接commit-->
        <property name="autoCommitOnClose" value="false"/>
        <!--获取连接超时时间,10秒-->
        <property name="checkoutTimeout" value="10000"/>
        <!--当前获取连接失败的次数-->
        <property name="acquireRetryAttempts" value="2"/>
    </bean>
    <!-- 3.配置SqlSessionFactory对象 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <!-- 扫描pojo包 使用别名 -->
        <property name="typeAliasesPackage" value="com.gaoliwei.pojo"/>
        <!-- 扫描sql配置文件:mapper需要的xml文件 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    </bean>

    <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 注入sqlSessionFactory -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <!-- 给出需要扫描Dao接口包 -->
        <property name="basePackage" value="com.gaoliwei.dao"/>
    </bean>

</beans>

spring-mvc layer configuration file

<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">
    <!--1、注解驱动-->
    <mvc:annotation-driven/>
    <!--2、静态资源过滤器-->
    <mvc:default-servlet-handler/>


    <!-- 3、扫描包:controller -->
    <context:component-scan base-package="com.gaoliwei.controller"/>
    <!-- 4、视图解析器  -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--前缀-->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!--后缀-->
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

spring-service business layer configuration

<?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">
    <!-- 扫描service包下所有使用注解的类型 -->
    <context:component-scan base-package="com.gaoliwei.service" />

    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 配置基于注解的声明式事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
</beans>
Project core class

NotesController control jump class

package com.gaoliwei.controller;

import com.gaoliwei.pojo.Notes;
import com.gaoliwei.service.NotesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/note")
public class NotesController {
    
    
    @Autowired
    private NotesService notesService;

    @RequestMapping("/allNotes")
    public String list(Model model) {
    
    
        List<Notes> list = notesService.queryAllNotes();
        model.addAttribute("list", list);
        return "allNotes";
    }

    @RequestMapping("/toAddNotes")
    public String toAddNotes(){
    
    
        return "addNotes";
    }

    @RequestMapping("/addNotes")
    public String addNotes(Notes notes) {
    
    

        notesService.addNotes(notes);
        return "redirect:/note/allNotes";
    }

    @RequestMapping("/del/{noteId}")
    public String deleteNotes(@PathVariable("noteId") Long id) {
    
    
        notesService.deleteNotesById(id);
        return "redirect:/note/allNotes";
    }

    @RequestMapping("toUpdateNotes")
    public String toUpdateNotes(Model model, Long id) {
    
    
        model.addAttribute("notes", notesService.queryById(id));
        return "update";
    }

    @RequestMapping("/updateNotes")
    public String updatePaper(Model model, Notes notes) {
    
    
        notesService.updateNotes(notes);
        notes = notesService.queryById(notes.getNoteId());
        model.addAttribute("notes", notes);
        return "redirect:/note/allNotes";
    }
}

NotesDao class mapping file NotesMapper.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.gaoliwei.dao.NotesDao">
    <resultMap type="Notes" id="notesResultMap" >
        <id property="noteId" column="noteId"/>
        <result property="noteContent" column="noteContent"/>
        <result property="author" column="author"/>
        <result property="date" column="date"/>
    </resultMap>
    <insert id="addNotes" parameterType="Notes">
        INSERT INTO notes(noteContent,author,date) VALUE (#{noteContent}, #{author}, #{date})
    </insert>

    <delete id="deleteNotesById" parameterType="long">
        DELETE FROM notes WHERE noteId=#{noteId}
    </delete>

    <update id="updateNotes" parameterType="Notes">
        UPDATE notes
        SET noteContent = #{noteContent},author = #{author},date = #{date}
        WHERE  noteId = #{noteId}
    </update>

    <select id="queryById" resultType="Notes" parameterType="long">
        SELECT noteId,noteContent,author,date
        FROM notes
        WHERE noteId=#{noteId}
    </select>
    <select id="queryAllNotes" resultMap="notesResultMap">
        SELECT noteId,noteContent,author,date
        FROM notes
    </select>

</mapper>

For more source code, please go to my github to download the source project

Demonstration results

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43479947/article/details/112132385