SSM 整合案例

news/2024/11/25 20:33:01/

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.ppmy.cn/news/415821.html

相关文章

山海经妖兽录服务器维护,山海经九州异兽录不能登录怎么解决

山海经九州异兽录不能登录怎么解决?最近有玩家在玩山海经九州异兽录的时候会出现不能登录的问题&#xff0c;那么这个问题要怎么解决呢?今天&#xff0c;小编将会给大家带来关于山海经九州异兽录不能登录的解决办法&#xff0c;希望大家会喜欢。 山海经九州异兽录不能登录解决…

九州云登榜“2022混合云TOP50”

混合云融合了公有云和私有云&#xff0c;因为可靠性、安全性、易用性和性价比等方面的综合表现近年来成为云计算的主要模式和发展方向。 日前&#xff0c;德本咨询、eNet研究院、互联网周刊联合发布“2022混合云TOP50”榜单&#xff0c;经过前期调研和综合评估&#xff0c;九州…

日本九州攻略

3.16-3.24 Day0 (3.16) 行程&#xff1a;浦东——福冈&#xff08;10:20-13:00&#xff09;&#xffe5;590 Day1 (3.17) 行程&#xff1a;桃园——福冈&#xff08;6:45-10:00&#xff09;&#xffe5;1176 美食&#xff1a;河豚料理&#xff0c;辛拉面 住宿&#xff1a…

九州云获颁“2021年度企业”荣誉奖

3月18日&#xff0c;中国科学院《互联网周刊》、中国社会科学院信息化研究中心、eNet研究院、德本咨询联合发布“2022&#xff08;第七届&#xff09;思维实验室论坛颁奖名单”&#xff0c;定位于对2021年度的深度发现和总结&#xff0c;评选出各行业、细分领域优秀人物、企业&…

android studio svn 提交不了,bet9九州手机版-官方网站

1.题目链接:http://acm.hdu.edu.cn/showproblem.php?pid5954 Problem DescriptionYou have got a cylindrical cup. Its bottom diameter is 2 units and its height is 2 units as well.The height of liquid level in the cup is d (0 ≤ d ≤ 2). When you incline the cup…

九州云难道仅仅是“运气好”?

就连全球闻名的OpenStack峰会都摇身一变成了开源基础设施峰会&#xff0c;国内那些因OpenStack而生的创业企业当然也不会守株待兔&#xff0c;而是积极求新求变。 01 从OpenStack来&#xff0c;到开源基础设施去 从2010年到2014年&#xff0c;这是OpenStack在国内市场“野蛮生长…

九州云上榜“2020边缘计算力量TOP20”

11月7日&#xff0c;由边缘计算社区主办的“全球边缘计算大会北京站”在北京新世界大酒店顺利召开。本次大会以“5G边缘计算”为主题&#xff0c;邀请了政、产、学、研、用各界的企业负责人、权威技术专家、通信科技从业者、边缘计算研究者、边缘计算投资机构负责人等出席&…

神武服务器物品,《神武4》装备鉴赏 欣赏一下这些神兵利器

各位少侠晚上好&#xff0c;自从本周话题“你的挚爱装备”发布以后小伙伴们踊跃投稿&#xff0c;各种特技特效的极品装备看的本昕眼花缭乱&#xff01;各位话不多说&#xff0c;一起来欣赏一下这些神兵利器&#xff01; 1、来自天星破月服务器的(小寒&#xff0e;)&#xff1a;…