一、《学生教务系统》之城市管理板块实现

简介: 《学生教务系统》之城市管理板块实现

《学生教务系统》之城市管理板块实现

一、城市管理实现前提

注意:在实现城市功能之前我们可以参考一下:《学生教务系统》立项需求说明书


(1)城市管理实现思路图


image.png

2、城市管理数据库设计(t_city)


image.png

注意:其中Studnet表中有t_city,所以我们建表时最好把城市表放在第一个建的表


create table t_city(
  id int primary key auto_increment ,
  name varchar(20) not null  unique
)

3、城市管理页面实现效果图


image.png

二、查询,删除,添加功能实现

(1)实体类(bean类)

public class City implements Serializable {
    private Integer cid;
    private String cname;

(2)dao接口

public interface CityDao{
    /**
     * 添加城市
     * @param city
     */
    public void insertCity(City city);
    /**
     * 删除城市
     * @param id
     */
    public void deleteCity(Integer id);
    /**
     * 查询所有
     * @return
     */
    public List<City> selectCity();
}

(3)Mybatis实现Dao接口

<mapper namespace="com.tjcu.dao.CityDao">
    <!--动态SQL语句-->
    <resultMap id="SelectCity" type="city">
        <id property="cid" column="c_id"></id>
        <result property="cname" column="c_name"></result>
    </resultMap>
    <!--添加城市-->
    <insert id="insertCity">
        insert into t_city
        values (#{cid}, #{cname})
    </insert>
    <!--删除城市-->
    <delete id="deleteCity">
        delete
        from t_city
        where c_id = #{id}
    </delete>
    <!--查询所有-->
    <select id="selectCity" resultMap="SelectCity">
        select c_id, c_name
        from t_city
    </select>
</mapper>

(4)Service接口和Service的实现类

Service接口

public interface CityService {
    /**
     * 添加城市
     * @param city
     */
    public void insertCity(City city);
    /**
     * 删除城市
     * @param id
     */
    public void deleteCity(Integer id);
    /**
     * 查询所有
     * @return
     */
    public List<City> selectCity();
}

Service实现

public class CityServiceImpl implements CityService {
    @Override
    public void insertCity(City city) {
        CityDao mapper = (CityDao) MybatisUtil.getMapper(CityDao.class);
        mapper.insertCity(city);
        MybatisUtil.commit();
    }
    @Override
    public void deleteCity(Integer id) {
        CityDao mapper = (CityDao) MybatisUtil.getMapper(CityDao.class);
        mapper.deleteCity(id);
        MybatisUtil.commit();
    }
    @Override
    public List<City> selectCity() {
        CityDao mapper = (CityDao) MybatisUtil.getMapper(CityDao.class);
        List<City> cities = mapper.selectCity();
        MybatisUtil.close();
        return cities;
    }

(5)Struts2实现Controller层

public class CityAction extends ActionSupport {
    private City city;
    private  List<City> cities;
    //添加城市
    public String insertCity() {
        CityService cityService = new CityServiceImpl();
        city.setCid(null);
        cityService.insertCity(city);
       return  SUCCESS;
    }
    //删除城市
    public String deleteCity() {
        CityService cityService = new CityServiceImpl();
        cityService.deleteCity(city.getCid());
        return  SUCCESS;
    }
   //展示成
    public String selectCity() {
        CityService cityService = new CityServiceImpl();
         cities = cityService.selectCity();
        return SUCCESS;
    }
    public City getCity() {
        return city;
    }
    public void setCity(City city) {
        this.city = city;
    }
    public List<City> getCities() {
        return cities;
    }
    public void setCities(List<City> cities) {
        this.cities = cities;
    }

(6)测试类

public class CityTest {
    @Test
    public void insert(){
        CityService cityService = new CityServiceImpl();
        City city = new City(null, "天津");
        cityService.insertCity(city);
    }
    @Test
    public void delete(){
        CityService cityService = new CityServiceImpl();
        cityService.deleteCity(2);
    }
    @Test
    public void select(){
        CityService cityService = new CityServiceImpl();
        List<City> cities = cityService.selectCity();
        for (City city : cities) {
            System.out.println(city);
        }
    }

(7)Web.xml中struts2过滤器配置(过滤器只需要配置,后续模块功能不再配置)

  <filter>
    <filter-name>struts</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

(8)Struts核心配置

<!--城市-->
    <package name="city" namespace="/city" extends="struts-default">
        <!--添加城市-->
        <action name="addCity" method="insertCity" class="com.tjcu.action.CityAction">
            <result name="success" type="redirectAction">showCity</result>
        </action>
        <!--删除城市-->
        <action name="dropCity" method="deleteCity" class="com.tjcu.action.CityAction">
            <result name="success" type="redirectAction">showCity</result>
        </action>
        <!--展示城市-->
        <action name="showCity" method="selectCity" class="com.tjcu.action.CityAction">
            <result name="success" type="dispatcher">/city/showCity.jsp</result>
        </action>
    </package>

(9)JSP页面

展示(删除)城市页面

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">
<head>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/bootstrap.min.css">
    <title>城市列表</title>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <input type="button" class="btn btn-success btn-sm" value="添加城市" onclick="location.href='addCity.jsp'"/>
        </div>
    </div>
    <div class="row" style="margin-top: 15px;">
        <div class="col-sm-12">
            <table class="table table-striped table-bordered table-hover">
                <tr>
                    <th>编号</th>
                    <th>名称</th>
                    <th>操作</th>
                </tr>
                <c:forEach var="city" items="${requestScope.cities}" varStatus="c">
                    <tr>
                        <%--使用jstl+EL进行排序--%>
                        <td>${c.count}</td>
                        <td>${city.cname}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/city/dropCity?city.cid=${city.cid}" class="btn btn-danger btn-sm">删除</a>
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</div>
</body>
</html>

添加城市页面

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" isELIgnored="false" %>
<html lang="en">
<head>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="../statics/css/bootstrap.min.css">
    <title>添加城市</title>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <form action="${pageContext.request.contextPath}/city/addCity" method="post">
                <div class="form-group">
                    <label>
                        城市名称:
                    </label>
                    <input type="text" class="form-control" name="city.cname"/>
                </div>
                <input type="submit" class="btn btn-success btn-block btn-sm" value="提交"/>
                <input type="button" class="btn btn-info btn-block btn-sm" value="返回上级" onclick="history.go(-1);"/>
            </form>
        </div>
    </div>
</div>
</body>
</html>
相关文章
|
JavaScript Java 关系型数据库
Springboot+vue的课程管理系统(教务管理系统)。Javaee项目,springboot vue前后端分离项目。
Springboot+vue的课程管理系统(教务管理系统)。Javaee项目,springboot vue前后端分离项目。
|
3天前
|
人工智能 自然语言处理 Shell
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
仅用3分钟,百炼调用满血版Deepseek-r1 API,享受百万免费Token。阿里云提供零门槛、快速部署的解决方案,支持云控制台和Cloud Shell两种方式,操作简便。Deepseek-r1满血版在推理能力上表现出色,尤其擅长数学、代码和自然语言处理任务,使用过程中无卡顿,体验丝滑。结合Chatbox工具,用户可轻松掌控模型,提升工作效率。阿里云大模型服务平台百炼不仅速度快,还确保数据安全,值得信赖。
157353 24
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
|
5天前
|
人工智能 API 网络安全
用DeepSeek,就在阿里云!四种方式助您快速使用 DeepSeek-R1 满血版!更有内部实战指导!
DeepSeek自发布以来,凭借卓越的技术性能和开源策略迅速吸引了全球关注。DeepSeek-R1作为系列中的佼佼者,在多个基准测试中超越现有顶尖模型,展现了强大的推理能力。然而,由于其爆火及受到黑客攻击,官网使用受限,影响用户体验。为解决这一问题,阿里云提供了多种解决方案。
17016 37
|
13天前
|
机器学习/深度学习 人工智能 自然语言处理
PAI Model Gallery 支持云上一键部署 DeepSeek-V3、DeepSeek-R1 系列模型
DeepSeek 系列模型以其卓越性能在全球范围内备受瞩目,多次评测中表现优异,性能接近甚至超越国际顶尖闭源模型(如OpenAI的GPT-4、Claude-3.5-Sonnet等)。企业用户和开发者可使用 PAI 平台一键部署 DeepSeek 系列模型,实现 DeepSeek 系列模型与现有业务的高效融合。
|
5天前
|
并行计算 PyTorch 算法框架/工具
本地部署DeepSeek模型
要在本地部署DeepSeek模型,需准备Linux(推荐Ubuntu 20.04+)或兼容的Windows/macOS环境,配备NVIDIA GPU(建议RTX 3060+)。安装Python 3.8+、PyTorch/TensorFlow等依赖,并通过官方渠道下载模型文件。配置模型后,编写推理脚本进行测试,可选使用FastAPI服务化部署或Docker容器化。注意资源监控和许可协议。
1311 8
|
13天前
|
人工智能 搜索推荐 Docker
手把手教你使用 Ollama 和 LobeChat 快速本地部署 DeepSeek R1 模型,创建个性化 AI 助手
DeepSeek R1 + LobeChat + Ollama:快速本地部署模型,创建个性化 AI 助手
3416 117
手把手教你使用 Ollama 和 LobeChat 快速本地部署 DeepSeek R1 模型,创建个性化 AI 助手
|
8天前
|
人工智能 自然语言处理 API
DeepSeek全尺寸模型上线阿里云百炼!
阿里云百炼平台近日上线了DeepSeek-V3、DeepSeek-R1及其蒸馏版本等六款全尺寸AI模型,参数量达671B,提供高达100万免费tokens。这些模型在数学、代码、自然语言推理等任务上表现出色,支持灵活调用和经济高效的解决方案,助力开发者和企业加速创新与数字化转型。示例代码展示了如何通过API使用DeepSeek-R1模型进行推理,用户可轻松获取思考过程和最终答案。
|
5天前
|
人工智能 自然语言处理 程序员
如何在通义灵码里用上DeepSeek-V3 和 DeepSeek-R1 满血版671B模型?
除了 AI 程序员的重磅上线外,近期通义灵码能力再升级全新上线模型选择功能,目前已经支持 Qwen2.5、DeepSeek-V3 和 R1系列模型,用户可以在 VSCode 和 JetBrains 里搜索并下载最新通义灵码插件,在输入框里选择模型,即可轻松切换模型。
934 14
|
12天前
|
API 开发工具 Python
阿里云PAI部署DeepSeek及调用
本文介绍如何在阿里云PAI EAS上部署DeepSeek模型,涵盖7B模型的部署、SDK和API调用。7B模型只需一张A10显卡,部署时间约10分钟。文章详细展示了模型信息查看、在线调试及通过OpenAI SDK和Python Requests进行调用的步骤,并附有测试结果和参考文档链接。
1938 9
阿里云PAI部署DeepSeek及调用
|
9天前
|
人工智能 数据可视化 Linux
【保姆级教程】3步搞定DeepSeek本地部署
DeepSeek在2025年春节期间突然爆火出圈。在目前DeepSeek的网站中,极不稳定,总是服务器繁忙,这时候本地部署就可以有效规避问题。本文以最浅显易懂的方式带读者一起完成DeepSeek-r1大模型的本地部署。

热门文章

最新文章