SSM 整合案例

news2024/10/6 6:02:32

Ssm整合

  • 注意事项
  1. Spring mvc+Spring+Mybatis+MySQL
  2. 项目结构,以web项目结构整合(还有maven、gradle)
  3. 整合日志、事务一个项目中
  4. Idea 2019、JDK12、Tomcat9、MySQL 5.5
  • 项目结构  D:\java\Idea\Idea_spacework\SSMhzy:不会就去找项目案例重新学习
  1. web项目为主结构,建立web目录,目录下有index.jsp和WEB-INF目录,WEB-INF目录可以放JSP文件。
  2. 配置文件建立在src目录下,Spring 容器配置文件bean.xml、Spring mvc请求处理配置springmvc-servlet.xml、Mybatis核心配置文件SqlConfig.xml。
  3. 程序代码存放位置,src目录下, 创建不同的包,dao、controller、service、pojo、util包存放不同的Java类
  4. JSP文件存放位置,WEB-INF目录下创建一个jsp目录,此目录下存储。
  5. 静态资源存放位置,在web目录下,和WEB-INF同一级目录创建res目录。

 

  • 引入jar包
  1. Spring、springmvc基础包及其依赖包
  2. Mybatis核心包及其依赖包
  3. 数据库驱动程序包
  4. 采用C标签,需要jstl-1.2.jar
  5. 引入spring框架和mybaits框架结合的jar,mybatis-spring-1.3.0.jar

 

  • 配置Tomcat服务器

 

  • 配置项目结构

 

 

  • 配置文件
  1. web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
<!--    spring mvc 核心控制器配置-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:bean.xml</param-value>
    </context-param>
<!--    spring容器上下文环境-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
<!--        spring mvc 的配置文件,放在当前项目src文件夹下-->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc-servlet.xml</param-value>
        </init-param>
<!--        spring mvc 的配置文件表示启动时优先加载本文件-->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
<!--    编码过滤器-->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

  1. bean.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
        https://www.springframework.org/schema/context/spring-context.xsd">
    <!--    开启Spring注解-->
    <context:component-scan base-package="inter.service"/>
    <!--    初始化数据源-->
    <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/school"></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
    </bean>
<!--        配置mybatissqlSessionFactory-->
        <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
            <!--扫描entity下的实体,方便mapper下的xml中使用别名,列如Depth则会找到zr.ssm.entity.Dept-->
            <property name="typeAliasesPackage" value="inter.pojo"/>
            <!--配置数据库连接池-->
            <property name="dataSource" ref="dataSource"/>
            <!--显示控制台SQL语句-->
            <property name="configLocation" value="classpath:sqlConfig.xml"></property>
            <!--自动扫描mapper下的XX.xml 文件-->
            <property name="mapperLocations" value="classpath:inter/dao/*.xml"/>
        </bean>
        <!--DAO接口所在包名,Spring会自动查找其它的类并注入到Spring的容器中-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="inter.dao"/>
        </bean>
</beans>

  1. Springmvc-servlet.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: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
        https://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
         https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--    spring 开启注解-->
    <context:component-scan base-package="inter.controller"/>

    <!--    视图解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--        前缀-->
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <!--        后缀-->
        <property name="suffix" value=".jsp"/>
    </bean>
<!--    静态资源处理器-->
    <!--        静态资源访问-->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!--    mapping 用户访问的URL路径;location:文件真实存放的路径-->
    <mvc:resources mapping="/css/**" location="/res/css/"/>
    <mvc:resources mapping="/js/**" location="/res/js/"/>
    <mvc:resources mapping="/img/**" location="/res/img/"/>
</beans>

  1. SqlConfig.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>
<!--定义在控制台上面输出sql语句-->
<settings>
    <setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
    <typeAliases>
        <typeAlias type="inter.pojo.User" alias="User"></typeAlias>
    </typeAliases>
</configuration>

  • 代码

包结构: inter

-->

controller

-->service

-->pojo

-->dao

-->util

Controller层下面的代码

package inter.controller;

import inter.pojo.StuTable;
import inter.pojo.eduCation;
import inter.service.EduService;
import inter.service.StuTableService;
import inter.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class StuTableController {
    @Autowired
    StuTableService stuTableService;
    @Autowired
    EduService eduService;
    //新增数据页面
    @RequestMapping(value = "/insertStuT")
    public ModelAndView insertStuT() {
        ModelAndView mv  = new ModelAndView();
        List<eduCation> eduList = eduService.showAllEdu();
        mv.addObject("eduList",eduList);
        mv.setViewName("insertStuT");
        return mv;
    }

    //保存新增数据
    @RequestMapping(value = "/saveStuT")
    public ModelAndView saveStuT(StuTable stuTable) {
        int num = stuTableService.saveStuT(stuTable);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("redirect:stuList");
        return mv;
    }

    //显示所有记录
    @RequestMapping(value = "/stuList")
    public ModelAndView showAllStu(String pageNow,StuTable stuTable) {
        ModelAndView mv = new ModelAndView();
        try {
            //获取总行数
            int totalCount = stuTableService.stuCount();
            Page page = null;

            if (pageNow!=null){
                page = new Page(totalCount,Integer.parseInt(pageNow));
            }else {
                page = new Page(totalCount,1);
            }
            StuTable stu = new StuTable();
            stu.setPageSize(page.getPageSize());
            stu.setStart(page.getStartPos());
            if (stuTable.getTel()!=null){
                stu.setTel(stuTable.getTel());
            }
            if (stuTable.getSname()!=null){
                stu.setTel(stuTable.getSname());
            }
            List<StuTable> list = stuTableService.showAllStu(stu);
            List<eduCation> eduList = eduService.showAllEdu();
            mv.addObject("eduList",eduList);
            mv.addObject("list", list);
            mv.addObject("page",page);
            mv.setViewName("stuList");
        }catch (Exception e){
            e.printStackTrace();
        }
        return mv;
    }

    //删除记录
    @RequestMapping(value = "/delStut")
    public ModelAndView delStu(int bh) {
        int sta = stuTableService.delStu(bh);
        ModelAndView mv = new ModelAndView();
        if (sta > 0) {
            mv.setViewName("redirect:stuList");
        }
        return mv;
    }

    //根据编号显示一条记录
    @RequestMapping(value = "/editStu1")
    public ModelAndView getStuByBh(int bh) {
        ModelAndView mv = new ModelAndView();
        StuTable stu1 = stuTableService.getStuByBh(bh);
        List<eduCation> eduList = eduService.showAllEdu();
        mv.addObject("eduList",eduList);
        mv.addObject("stu", stu1);
        mv.setViewName("editStu");
        return mv;
    }

    //修改数据
    @RequestMapping(value = "/updateStu")
    public String updateStu(StuTable stuTable) {
        int sta1 = stuTableService.updateStu(stuTable);
        return "redirect:stuList";//重定向,自动携带数据
    }
    //显示详情页面
    @RequestMapping (value = "/tipStu")
    public ModelAndView tipStu(int bh){
        ModelAndView mv = new ModelAndView();
        StuTable stu2 = stuTableService.getStuByBh(bh);
        mv.addObject("stu1", stu2);
        mv.setViewName("tipStu");
        return mv;
    }



}

Service下面的代码


package inter.service;

import inter.dao.IStuTableDao;
import inter.pojo.StuTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StuTableService {
    @Autowired
    IStuTableDao tableDao;
    //新增
    @Transactional
    public int saveStuT(StuTable stu){
        int num = tableDao.saveStuT(stu);
        return num;
    }
    //显示所有
    public List<StuTable> showAllStu(StuTable stuTable) {
        return tableDao.showAllStu(stuTable);
    }
    //删除记录
    public int delStu(int bh){
        return tableDao.delStu(bh);
    }
    //显示一条记录
    public StuTable getStuByBh(int bh){
        return tableDao.getStuByBh(bh);
    }
    //修改
    public int updateStu(StuTable stuTable){
        return  tableDao.updateStu(stuTable);
    }
    //显示记录数
    public int stuCount(){
        return tableDao.stuCount();
    }


    public IStuTableDao getTableDao() {
        return tableDao;
    }

    public void setTableDao(IStuTableDao tableDao) {
        this.tableDao = tableDao;
    }
}

 Pojo 代码

package inter.pojo;

public class StuTable {
    private int bh;
    private String sname;
    private String tel;
    private String birthday;
    private String gender;
    private String xl;
    private double cj;
    private String grqk;
    //下面两个参数,只是供传参使用
    private int start;//索引开始位置
    private int pageSize;//数据显示记录数

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getBh() {
        return bh;
    }

    public void setBh(int bh) {
        this.bh = bh;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getXl() {
        return xl;
    }

    public void setXl(String xl) {
        this.xl = xl;
    }

    public double getCj() {
        return cj;
    }

    public void setCj(double cj) {
        this.cj = cj;
    }

    public String getGrqk() {
        return grqk;
    }

    public void setGrqk(String grqk) {
        this.grqk = grqk;
    }
}

Dao 代码

package inter.dao;

import inter.pojo.StuTable;

import java.util.List;

public interface IStuTableDao {
    //数据保存
    int saveStuT(StuTable stuTable);

    //显示所有
    List<StuTable> showAllStu(StuTable stuTable);

    //删除
    int delStu(int bh);

    //根据编号显示一条记录
    StuTable getStuByBh(int bh);

    //修改
    int updateStu(StuTable stuTable);

    //显示记录数
    int stuCount();


}

Util 工具类 里面


package inter.util;

public class Page {
    private int pageNow=1; //当前页数
    private int pageSize=5; //每页显示的数量
    private int totalCount; //总记录数
    private int totalPageCount; //总页数
    private int startPos; //开始位置,从0开始
    private boolean hasFrist; //是否有首页
    private boolean hasPre; //是否有前一页
    private boolean hasNext; //是否有后一页
    private boolean hasLast; //是否有尾页 /**

    //通过构造函数,传入总记录数和当前页
    public Page(int totalCount, int pageNow){
        this.totalCount=totalCount;
        this.pageNow=pageNow;
    }
    //获取总页数
    public int getTotalPageCount() {
        totalPageCount=getTotalCount()/getPageSize();
        return (totalCount%pageSize==0)?totalPageCount:totalPageCount+1;
    }
    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    //获取选择记录的初始位置
    public int getStartPos() {
        return (pageNow-1)*pageSize;
    }

    public void setStartPos(int startPos) {
        this.startPos = startPos;
    }
    //判断是否有第一页
    public boolean isHasFrist() {
        return (pageNow==1) ? false:true;
    }
    public void setHasFrist(boolean hasFrist) {
        this.hasFrist = hasFrist;
    }
    //如果有首页就有前一页
    public boolean isHasPre() {
        return isHasFrist() ? true:false;
    }
    public void setHasPre(boolean hasPre) {
        this.hasPre = hasPre;
    }
    //如果有尾页就有下一页
    public boolean isHasNext() {
        return isHasNext() ? true:false;
    }
    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }
    //判断是否有尾页
    public boolean isHasLast() {
        return (pageNow==getTotalCount()) ? false:true;
    }
    public void setHasLast(boolean hasLast) {
        this.hasLast = hasLast;
    }


    public int getPageNow() {
        return pageNow;
    }

    public void setPageNow(int pageNow) {
        this.pageNow = pageNow;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }


}

JSP 页面代码部分

修改页面

<%@ page import="inter.pojo.StuTable" %><%--
  Created by IntelliJ IDEA.
  User: shun
  Date: 2023/6/6
  Time: 20:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>根据编号显示一条记录</title>
</head>
<body>
<form method="post" action="/updateStu">
<table border="1" cellpadding="16" cellspacing="0">
    <tr>
        <th colspan="2">修改页面</th>
    </tr>
    <tr>
        <th>编号</th>
        <td>
            ${stu.bh}
            <input type="hidden" name="bh" value="${stu.bh}">
        </td>
    </tr>
    <tr>
        <th>姓名</th>
        <td>
            <input type="text" placeholder="请输入姓名" name="sname" value="${stu.sname}">
        </td>
    </tr>
    <tr>
        <th>电话</th>
        <td>
            <input type="text" placeholder="请输入电话" name="tel" value="${stu.tel}">
        </td>
    </tr>
    <tr>
        <th>生日</th>
        <td>
            <input type="text" placeholder="请输入生日" name="birthday" value="${stu.birthday}">
        </td>
    </tr>
    <tr>
        <th>性别</th>
        <td>
            <c:if test="${stu.gender==1}">
                <input type="radio" name="gender" value="1"  checked>
                <input type="radio" name="gender" value="0">
            </c:if>
            <c:if test="${stu.gender==0}">
                <input type="radio" name="gender" value="1">
                <input type="radio" name="gender" value="0" checked>
            </c:if>
        </td>
    </tr>
    <tr>
        <th>学历</th>
        <td>
                <select name="xl">
                    <c:forEach items="${eduList}" var="edu">
                    <option value="${edu.edubh}" <c:if test="${edu.edubh==stu.xl}">selected</c:if>>${edu.eduname}</option>
                    </c:forEach>
                </select>
        </td>
    </tr>
    <tr>
        <th>成绩</th>
        <td>
            <input type="text" placeholder="请输入成绩" name="cj" value="${stu.cj}">
        </td>
    </tr>
    <tr>
        <th>个人情况</th>
        <td>
            <input type="text" placeholder="请输入个人情况" name="grqk" value="${stu.grqk}">
        </td>
    </tr>
    <tr>
        <th>修改</th>
        <td>
            <input type="submit" value="修改">
        </td>
    </tr>
</table>
    </form>
</body>
</html>

新增页面

<%--
  Created by IntelliJ IDEA.
  User: shun
  Date: 2023/6/5
  Time: 19:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>信息输入</title>
</head>
<body>
    <h1>用户输入</h1>
    <form action="/saveStuT" method="post">
        <input type="text" name="sname" placeholder="请输入姓名"><br>
        <input type="text" name="tel" placeholder="请输入手机号"><br>
        <input type="text" name="birthday" placeholder="请输入出生日期"><br>
        <input type="radio" value="1" name="gender">
        <input type="radio" value="0" name="gender"><br>
        <select name="xl">
            <c:forEach items="${eduList}" var="eduList">
                <option value="${eduList.edubh}">${eduList.eduname}</option>
            </c:forEach>
        </select>
        <br>
        <input type="text" name="cj" placeholder="请输入成绩"><br>
        <input type="text"  name="grqk" placeholder="请输入个人情况"><br>
        <input type="submit" value="保存">
    </form>
</body>
</html>

显示页面

<%--
  Created by IntelliJ IDEA.
  User: shun
  Date: 2023/6/6
  Time: 19:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>显示所有记录</title>
    <style>
        a {
            text-decoration: none;
            font-size: 20px;
        }
    </style>
</head>
<body>
<table border="1px" cellspacing="0" cellpadding="10" align="center">
    <tr>
        <th colspan="8">
            <a href="/insertStuT">新增数据</a>
            <form method="post" action="/stuList" style="display:inline-block">
                <input type="text" name="username" placeholder="请输入查询姓名">
                <input type="text" name="tel" placeholder="请输入查询电话">
                <input type="submit" value="查询"/>
            </form>
        </th>
    </tr>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>电话</th>
        <th>性别</th>
        <th>学历</th>
        <th>成绩</th>
        <th>个人情况</th>
        <th>操作</th>
    </tr>
    <c:forEach items="${list}" var="stu">
        <tr>
            <td>${stu.bh}</td>
            <td>${stu.sname}</td>
            <td>${stu.tel}</td>
            <td>
                <c:if test="${stu.gender==1}">
                    
                </c:if>
                <c:if test="${stu.gender==0}">
                    
                </c:if>
            </td>
            <td>
                <c:forEach items="${eduList}" var="edu">
                    <c:if test="${edu.edubh==stu.xl}">
                        ${edu.eduname}
                    </c:if>
                </c:forEach>
            </td>
            <td>${stu.cj}</td>
            <td>${stu.grqk}</td>
            <td>
                <a href="/delStut?bh=${stu.bh}">删除</a>
                <a href="/editStu1?bh=${stu.bh}">修改</a>
                <a href="/tipStu?bh=${stu.bh}">详情</a>
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="8">
            <div style="text-align: center">
                <font size=2>
                    ${page.totalPageCount}
                </font>
                <font size=2>
                    ${page.pageNow}
                </font>
                <a href="/stuList?pageNow=1">首页</a>
                <c:choose>
                    <c:when test="${page.pageNow - 1 > 0}">
                        <a href="/stuList?pageNow=${page.pageNow - 1}">上一页</a>
                    </c:when>
                    <c:when test="${page.pageNow - 1 <= 0}">
                        <a href="/stuList?pageNow=1">上一页</a>
                    </c:when>
                </c:choose>
                <c:choose>
                    <c:when test="${page.totalPageCount==0}">
                        <a href="/stuList?pageNow=${page.pageNow}">下一页</a>
                    </c:when>
                    <c:when test="${page.pageNow + 1 < page.totalPageCount}">
                        <a href="/stuList?pageNow=${page.pageNow + 1}">下一页</a>
                    </c:when>
                    <c:when test="${page.pageNow + 1 >= page.totalPageCount}">
                        <a href="/stuList?pageNow=${page.totalPageCount}">下一页</a>
                    </c:when>
                </c:choose>
                <c:choose>
                    <c:when test="${page.totalPageCount==0}">
                        <a href="/stuList?pageNow=${page.pageNow}">尾页</a>
                    </c:when>
                    <c:otherwise>
                        <a href="/stuList?pageNow=${page.totalPageCount}">尾页</a>
                    </c:otherwise>
                </c:choose>
            </div>
        </td>
    </tr>
</table>
</body>
</html>

详细页面

<%--
  Created by IntelliJ IDEA.
  User: shun
  Date: 2023/6/6
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>详细</title>
</head>
<body>
<table border="1" cellpadding="16" cellspacing="0">
    <tr>
        <th colspan="2">详细页面</th>
    </tr>
    <tr>
        <th>编号</th>
        <td>
            ${stu1.bh}
        </td>
    </tr>
    <tr>
        <th>姓名</th>
        <td>
           ${stu1.sname}
        </td>
    </tr>
    <tr>
        <th>电话</th>
        <td>
           ${stu1.tel}
        </td>
    </tr>
    <tr>
        <th>生日</th>
        <td>
          ${stu1.birthday}
        </td>
    </tr>
    <tr>
        <th>性别</th>
        <td>
          ${stu1.gender}
        </td>
    </tr>
    <tr>
        <th>学历</th>
        <td>
            ${stu1.xl}
        </td>
    </tr>
    <tr>
        <th>成绩</th>
        <td>
            ${stu1.cj}
        </td>
    </tr>
    <tr>
        <th>个人情况</th>
        <td>
          ${stu1.grqk}
        </td>
    </tr>
</table>
</body>
</html>

  • 运行

使用Tomcat运行,在浏览器中显示

显示页面

 

新增数据页面

 

修改页面

 

详细页面

 

  • 配置日志

在src下创建一个log4j.properties文件配置日志

# Global logging configuration
log4j.rootLogger = DEBUG,stdout
#Console output...
log4j.appender.stdout= org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

  • 配置事务

在 bean.xml 文件中配置


  <!--扫描事务管理器,创建一个事务管理器-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
<!--    开启事务注解,标注@Transactional的类和方法将具有事务性
    那些方法需要事务就在那个方法上写一个@Transactional 这个标记
-->
<!--    注解方式配置事务-->
    <tx:annotation-driven transaction-manager="transactionManager"/>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/652508.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

chatgpt赋能python:Python怎么筛选奇数

Python怎么筛选奇数 Python是一种高级编程语言&#xff0c;既具有面向对象编程的特点&#xff0c;又可以进行函数式编程。Python的语法简洁、清晰&#xff0c;非常适合初学者学习。在Python中&#xff0c;筛选奇数的方法非常简单&#xff0c;本文将介绍Python中筛选奇数的方法…

人机交互学习-5 交互式系统的需求

交互式系统的需求 需求是什么需求需求活动 产品特性用户特性体验水平差异新手用户专家用户中间用户 年龄差异老年人儿童 文化差异健康差异 用户建模人物角色人物角色的作用人物角色的构造错误观点人物角色基于问题举例注意事项 建模过程 需求获取、分析和验证观察场景人物角色场…

爬虫数据是如何收集和整理的?

爬虫数据的收集和整理通常包括以下步骤&#xff1a; 确定数据需求&#xff1a;确定要收集的信息类型、来源和范围。 网络爬取&#xff1a;使用编程工具&#xff08;如Python的Scrapy、BeautifulSoup等&#xff09;编写爬虫程序&#xff0c;通过HTTP请求获取网页内容&#xff…

网卡命名规则和网卡变动结论

net.ifnames0 biosdevname0 插卡前状态&#xff1a; 插卡后状态&#xff1a; 结论&#xff1a;明显eth0 MAC地址从00:0d:48:94:10:fc 变更为 c0:33:da:10:31:ff。该方法eth0实际对应的网口发生了变动。 net.ifname1 插卡前状态&#xff1a; 插卡后状态&#xff1a; 查看…

MEC | 条款2 最好使用C++转型操作符

条款2 最好使用C转型操作符 文章目录 条款2 最好使用C转型操作符c4个转型操作符static_castconst_castdynamic_castreinterpret_cast 宏模仿新转换语法欢迎关注公众号【三戒纪元】 c4个转型操作符 static_castconst_castdynamic_castreinterpret_cast 原因是 新式转型方法容…

chatgpt赋能python:Python在SEO中如何确定主语?

Python在SEO中如何确定主语&#xff1f; Python是一种高级编程语言&#xff0c;广泛应用于Web开发、数据分析和机器学习等领域。但是&#xff0c;Python编写的网页是否符合SEO标准&#xff0c;是一个需要重视的问题。在SEO中&#xff0c;主语是一个非常重要的因素。那么&#…

CLickhouse 物化视图--干货记录(亲验证)

1、普通视图VS物化视图 普通视图不保存数据&#xff0c;保存的仅仅是查询语句&#xff0c;查询的时候还是从原表读取数据&#xff0c;可以将普通视图理解为是个子查询。--中看不中用 物化视图则是把查询的结果根据相应的引擎存入到了磁盘或内存中&#xff0c;对数据重新进行了…

Duilib中禁止一个窗口双击最大化

1、Duilib中禁止一个窗口双击最大化 用duilib开发了一个窗口&#xff0c;比如是登录窗口&#xff0c;那么这个窗口的窗口的双击最大化就毫无意义&#xff0c;甚至带来灾难&#xff0c;我们就要明确禁止这样的行为。 我们应该明确&#xff0c;一个窗口创建的时候就赋予了它一些…

内核链表、JSON的序列化与反序列化

1) 结构体变量的首地址能够被其最宽基本类型成员的大小所整除&#xff1b; 2) 结构体每个成员相对结构体首地址的偏移量(offset)都是成员大小的整数倍&#xff0c;如有需要编译器会在成员之间加上填充字节(internal adding)&#xff1b; 3) 结构体的总大小为结构体最宽基本类型…

计算机组成原理(考研408)练习题#3

用于复习408或计算机组成原理期末考试。如有错误请在评论区指出。 So lets start studying with questions! それでは、問題の勉強を始めましょう&#xff01; 1. 定点整数原码编码[x]原1110100B 的真值为_________。 首先&#xff0c;1110100B是一个8位二进制数&#xff0c…

Spring Cloud Sleuth使用简介

Spring-Cloud Spring Cloud为开发者提供了在分布式系统(如配置管理、服务发现、断路器、智能路由、微代理、控制总线、一次性Token、全局锁、决策竞选、分布式会话和集群状态)操作的开发工具。使用SpringCloud开发者可以快速实现上述这些模式。 SpringCloud Sleuth Distribu…

【0基础教程】Javascript 正则表达式里的分组捕捉 Capturing Groups 使用方法及原理

一、从最简单开始 现有一个字符串&#xff1a; “1-apple” 需要解析出 1 和 apple 来&#xff0c;对应的正则表达式很简单&#xff1a; ^(\d)-(.)$ 其中&#xff0c; ^ 表示字符串的开始&#xff0c;然后一个圆括号包裹的内容表示一个"组"&#xff1a;(\d) 表示一组…

【深度学习】2-1 神经网络 - 激活函数

激活函数 将输入信号的总和转换为输出信号&#xff0c;一般称为激活函数&#xff08;activation function&#xff09;。激活函数作用在于决定如何来激活输入信号的总和。 对激活函数&#xff0c;一般要求&#xff1a; 非线性&#xff1a;为提高模型的学习能力&#xff0c;如…

Nginx reuseport导致偶发性卡顿

背景 从2018年开始&#xff0c;我们有个业务陆续接到反馈 Nginx 线上集群经常出现不响应或者偶发性的“超慢”请求。这种卡顿每天都有少量出现。而只有多个集群中的一个出现&#xff0c;其他压力更大的集群皆未出现。 业务结构比较简单&#xff1a;LVS->Nginx->后端&…

Advanced-C.01.基础知识

C语言程序设计概述 一个简单句的C程序 #include <stdio.h> int main(){printf("This is a C program.\n");retrun 0; }C程序的执行过程 数据单位 bit&#xff1a;位&#xff0c;计算机中最小的数据单位Byte&#xff1a;字节&#xff0c;计算机中信息组织和存…

C++ 搜索二叉树

目录 C 搜索二叉树一. 介绍二.简单实现搜索二叉树1. 基本框架2. 插入节点a. 图示&#xff1a;b. 递归实现&#xff1a;c. 非递归&#xff1a; 3. 删除节点a. 图示&#xff1a;b. 递归实现&#xff1a;c. 非递归&#xff1a; 三. 小结 C 搜索二叉树 又名&#xff1a;二叉搜索树…

bean的三种实例化方式

实例化bean的三种方式&#xff0c;构造方法,静态工厂和实例工厂 构造方法实例化&#xff08;常用&#xff09; 步骤1&#xff1a;准备一个BookDao和BookDaoImpl类 public interface BookDao {public void save(); } ​ public class BookDaoImpl implements BookDao {public…

Vue中如何进行表单图片裁剪与预览

Vue中如何进行表单图片裁剪与预览 在前端开发中&#xff0c;表单提交是一个常见的操作。有时候&#xff0c;我们需要上传图片&#xff0c;但是上传的图片可能会非常大&#xff0c;这会增加服务器的负担&#xff0c;同时也会降低用户的体验。因此&#xff0c;我们通常需要对上传…

Python:关于flask框架的flask_scrip._compat

关于flask框架的flask_scrip._compat compat是什么源码Flask版本书写不同 compat是什么 compat 英文单词同胞的意思 compat的功能是在py的不同版本之间做兼容处理 一些py2/py3兼容性支持基于精简版的six&#xff0c;因此我们不必依赖于它的特定版本。 源码 # -*- coding: u…

使用芯片和贴片天线解决多频带射频问题

智能手机和可穿戴电子设备等手持和便携式无线产品依赖可置入设备的微型芯片、贴片和印制线天线。尽管这些小型器件解决了在小尺寸系统中携带多频带天线阵列的问题&#xff0c;但它们也引入了辐射效率下降、阻抗匹配以及与附近物体和人体的交互等相关问题。 为解决这些问题&…