Spring练习-CRUD操作[2]-角色列表的展示

本文详细介绍了在Spring环境下实现角色列表的CRUD操作。从步骤分析开始,包括点击角色管理菜单触发请求、创建Controller、Service、Dao各层代码,到配置文件设置,再到JdbcTemplate的使用和JSP页面展示。最后,通过打包部署到Tomcat并测试,确保功能正常运行。
摘要由CSDN通过智能技术生成

Spring练习-CRUD操作[2]-角色列表的展示

1.步骤分析

① 点击角色管理菜单发送请求到服务器端(修改角色管理菜单的url地址)
② 创建RoleController和showList()方法
③ 创建RoleService和showList()方法
④ 创建RoleDao和findAll()方法
⑤ 使用JdbcTemplate完成查询操作
⑦ 将查询数据存储到Model中 ,转发到role-list.jsp页面进行展示

2.测试打包发布空项目(只有静态页面)

1.打包并将项目部署到tomcat

(1)打包项目:
在这里插入图片描述
(2)将项目部署到tomcat:
在这里插入图片描述

(3)运行tomcat,测试:
在这里插入图片描述在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3.编写后台代码

3.1 配置文件

1.配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       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
        http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
    <!--引入spring-mvc.xml-->
    <import resource="classpath:spring-mvc.xml"/>
    <!--引入jdbc.rpoperties-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!--扫描dao,service下的包-->
    <context:component-scan base-package="com.itspring.dao,com.itspring.service"/>
    <!--配置c3p0数据库连接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    <!--配置spring jdbc,并将c3p0连接池注入-->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"/>
    </bean>


</beans>

2.配置spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       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
       http://www.springframework.org/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值