ssh_maven之controller层开发
我们已经完成了前两层的开发,现在 只剩下我们的controller层了,对于这一层,我们需要创建一个动作类CustomerAction,另外就是我们的strutss.xml以及我们的applicationContext-web.xml,还有我们的web.xml中,我们需要配置我们的配置我们的struts的核心过滤器StrutsPrepareAndExecutorFilter,除此之外,就是spring的监听器以及对spring中的参数的配置
我们是maven项目,我们需要引入我们的service,下面是我们的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.itheima</groupId>
<artifactId>ssh_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ssh_controller</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssh_service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
开始写我们的CustomerAction
package com.itheima.web.action; import java.util.List; import com.itheima.entity.Customer;
import com.itheima.service.CustomerService;
import com.opensymphony.xwork2.ActionSupport; public class CustomerAction extends ActionSupport {
private CustomerService customerService; private List<Customer> customers; public List<Customer> getCustomers() {
return customers;
} public void setCustomers(List<Customer> customers) {
this.customers = customers;
} public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
} public String findAllCustomer(){
customers = customerService.findAllCustomer();
return this.SUCCESS;
}
public String saveCustomerUI(){
return this.SUCCESS;
}
}
然后写我们的applicationContext-web.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<import resource="classpath:applicationContext-service.xml"/>
<bean id="customerAction" class="com.itheima.web.action.CustomerAction">
<property name="customerService" ref="customerService"></property>
</bean>
</beans>
随后是我们的struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="customer" namespace="/customer" extends="struts-default">
<action name="findAllCustomer" class="customerAction" method="findAllCustomer">
<result name="success">/jsp/customer/list.jsp</result>
</action>
<action name="saveCustomerUI" class="customerAction" method="saveCustomerUI">
<result name="success">/jsp/customer/add.jsp</result>
</action>
</package>
</struts>
这样的话,就剩下我们的web.xml文件了
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>ssh_controller</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置struts的过滤器 -->
<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>
<!-- 配置spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 监听器启动的参数 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-web.xml</param-value>
</context-param>
</web-app>
这样的话,我们的controller层也OK了,现在我们可以使用我们的maven命令运行我们的项目tomcat:run
点键我们的父工程,即右键ssh_parent,->Run AS->Maven builder..在出来的页面中输入我们的命令即可
这样的话,我们在浏览器访问我们的路径http://localhost:8080/ssh_controller,我们的页面还是使用之前的页面
这样我们的一个完整的ssh结合maven就整合完成了!
ssh_maven之controller层开发的更多相关文章
- SpringMVC综合使用手机管理系统Controller层开发
1. beans.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu ...
- DAO层,Service层,Controller层、View层 的分工合作
DAO层:DAO层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DAO的接口,然后在Spring的配置文件中定义此接口的实现类,然后就可在模块中调用此接口 ...
- [转]DAO层,Service层,Controller层、View层
来自:http://jonsion.javaeye.com/blog/592335 DAO层 DAO 层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DA ...
- DAO(Repository),Service,Controller层之间的相互关系
DAO层:DAO层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DAO的接口,然后在Spring的配置文件中定义此接口的实现类,然后就可在模块中调用此接口 ...
- 【统一异常处理】@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常
1.利用springmvc注解对Controller层异常全局处理 对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service ...
- ssm框架中Controller层的junit测试_我改
Controller测试和一般其他层的junit测试可以共用一个BaseTest 一.BaseTest如下: @RunWith(SpringJUnit4ClassRunner.class) @WebA ...
- DAO层,Service层,Controller层、View层
DAO层:DAO层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DAO的接口,然后在Spring的配置文件中定义此接口的实现类,然后就可在模块中调用此接口 ...
- 分层 DAO层,Service层,Controller层、View层
前部分摘录自:http://blog.csdn.net/zdwzzu2006/article/details/6053006 DAO层:DAO层主要是做数据持久层的工作,负责与数据库进行联络的一些任务 ...
- DAO层,Service层,Controller层、View层介绍
来自:http://jonsion.javaeye.com/blog/592335 DAO层 DAO 层主要是做数据持久层的工作,负责与数据库进行联络的一些任务都封装在此,DAO层的设计首先是设计DA ...
随机推荐
- Unity3D 打包Standalone(exe文件) Shader丢失
Shader丢失算是老生常谈了 从刚开始接触Unity时,从别的地方拿过来模型导入 就认识了一个标志性的颜色 就是粉色,或者是紫色 当在Unity中遇到这种颜色 不用怀疑 绝对是Shader或者材质丢 ...
- MySQL DBA教程全套视频资料
MySQL基础入门.MySQL多实例安装与企业应用场景.MySQL应用管理及进阶实战操作.MySQL乱码问题及字符集实战.MySQL备份-增量备份及数据恢复基础实战.MySQL主从复制原理及实战部署. ...
- NET Core2.0 Memcached踩坑,基于EnyimMemcachedCore整理MemcachedHelper帮助类。
DotNetCore2.0下使用memcached缓存. Memcached目前微软暂未支持,暂只支持Redis,由于项目历史原因,先用博客园开源项目EnyimMemcachedCore,后续用到的时 ...
- Java 类文件结构
Java 诞生之时有句著名的宣传口号"Write Once, Run Anywhere.".但是,Java 语言本身不具备跨平台的能力,而是 JVM 提供了跨平台的能力. 事实上, ...
- scanf()中的%c 不能正常输入的问题
#include <stdio.h> int main() { char a; int b; scanf("%d",&b); scanf("%c&qu ...
- 前端Blob对二进制流数据的处理方式
var xhr = new XMLHttpRequest(); xhr.open("post", "/login/getCaptcher?t=" + Math. ...
- C语言描述栈的实现及操作(数组实现)
一.静态数组实现 1.堆栈接口 // 一个堆栈模块接口 // 命名为stack.h #define STACK_YTPE int // 堆栈所存储值的类型 // push函数 // 把一个新值压入栈中 ...
- mysql新手入门随笔2
17.创建表 CREATE TABLE tbname(columnname1 类型 约束条件, columnname2 类型 约束条件,-); 三大类型:数值型,时间日期型,字符串类型 六大约束条件: ...
- 使用责任链模式消除if分支实践
之前接手过一个车辆监控的工具,接受第三方推送过来的车辆状态数据然后入库.车辆状态一共有8种之多,每种状态都需要做不同 处理操作.刚接手这份代码时,针对此处处理,是庞大的if-else结构,if-els ...
- 使用ADO.NET查询和访问数据库
使用ADO.NET查询和访问数据库步骤 使用ADO.NET查询和访问数据库 连接数据库操作: 1. 定义连接字符串: String connString = "Data Sour ...