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/