maven整合ssh框架笔记
具体工程会上传文件sshpro
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>hello.HelloServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping> <!-- 配置struts2核心过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</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.xml</param-value>
</context-param> <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> </web-app>
<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:aop="http://www.springframework.org/schema/aop" 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/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
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/maven" />
<property name="user" value="root" />
<property name="password" value="123456" />
</bean> <!-- 配置sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 依赖dataSource -->
<property name="dataSource" ref="dataSource" />
<!-- 创建工厂需要加载hibernate映射文件 -->
<property name="configLocations" value="classpath:hibernate.cfg.xml"></property>
</bean> <bean id="customerDao" class="customerDaoImpl.CustomerImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <bean id="customerService" class="customerServiceImpl.CustomerServiceImpl">
<property name="customerDao" ref="customerDao"></property>
</bean> <bean id="customerAction" class="customerAction.CustomerAction">
<property name="customerService" ref="customerService"></property>
</bean> </beans>
<?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>
<!-- 配置常量 -->
<!-- 字符集 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!-- 开发模式 -->
<constant name="struts.devMode" value="true"></constant>
<!-- 主题 -->
<constant name="struts.ui.theme" value="simple"></constant>
<!-- 扩展名 -->
<constant name="struts.action.extension" value="action,,"></constant> <!-- 通用package -->
<package name="customer" namespace="/" extends="struts-default"> <action name="CustomerAction_*" class="customerAction" method="{1}">
<result name="success">/success.jsp</result>
</action> </package>
</struts>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration>
<!-- 会话工厂 -->
<session-factory>
<!-- 数据库方言,根据数据库选择 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property> <!--为了方便调试是否在运行hibernate时在日志中输出sql语句 -->
<property name="hibernate.show_sql">true</property>
<!-- 是否对日志中输出的sql语句进行格式化 -->
<property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="current_session_context_class">thread</property> <!-- 加载映射文件 -->
<mapping resource="domain/Customer.hbm.xml"/>
</session-factory> </hibernate-configuration>
文件结构图:
package domain; public class Customer {
private Long custId;
private String custName;
private Long custUserId;
private Long custCreateId;
private String custIndustry;
private String custLevel;
private String custLinkman;
private String custPhone;
private String custMobile;
public Long getCustId() {
return custId;
}
public void setCustId(Long custId) {
this.custId = custId;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
public Long getCustUserId() {
return custUserId;
}
public void setCustUserId(Long custUserId) {
this.custUserId = custUserId;
}
public Long getCustCreateId() {
return custCreateId;
}
public void setCustCreateId(Long custCreateId) {
this.custCreateId = custCreateId;
}
public String getCustIndustry() {
return custIndustry;
}
public void setCustIndustry(String custIndustry) {
this.custIndustry = custIndustry;
}
public String getCustLevel() {
return custLevel;
}
public void setCustLevel(String custLevel) {
this.custLevel = custLevel;
}
public String getCustLinkman() {
return custLinkman;
}
public void setCustLinkman(String custLinkman) {
this.custLinkman = custLinkman;
}
public String getCustPhone() {
return custPhone;
}
public void setCustPhone(String custPhone) {
this.custPhone = custPhone;
}
public String getCustMobile() {
return custMobile;
}
public void setCustMobile(String custMobile) {
this.custMobile = custMobile;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Customer [custId=" + custId + ", custName=" + custName
+ ", custUserId=" + custUserId + ", custCreateId="
+ custCreateId + ", custIndustry=" + custIndustry
+ ", custLevel=" + custLevel + ", custLinkman=" + custLinkman
+ ", custPhone=" + custPhone + ", custMobile=" + custMobile
+ "]";
} }
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 2016-2-26 16:58:40 by Hibernate Tools 4.3.1.Final -->
<hibernate-mapping>
<class name="domain.Customer" table="cst_customer" optimistic-lock="version">
<id name="custId" type="java.lang.Long">
<column name="cust_id" />
<generator class="identity" />
</id>
<property name="custName" type="string">
<column name="cust_name" length="32" not-null="true"></column>
</property>
<property name="custUserId" type="java.lang.Long">
<column name="cust_user_id"></column>
</property>
<property name="custCreateId" type="java.lang.Long">
<column name="cust_create_id"></column>
</property>
<property name="custIndustry" type="string">
<column name="cust_industry" length="32"></column>
</property>
<property name="custLevel" type="string">
<column name="cust_level" length="32"></column>
</property>
<property name="custLinkman" type="string">
<column name="cust_linkman" length="64"></column>
</property>
<property name="custPhone" type="string">
<column name="cust_phone" length="64"></column>
</property>
<property name="custMobile" type="string">
<column name="cust_mobile" length="16"></column>
</property>
</class>
</hibernate-mapping>
package customerAction; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; import customerService.CustomerService;
import domain.Customer; public class CustomerAction extends ActionSupport{ private String id;
private CustomerService customerService;
private Customer customer; public CustomerService getCustomerService() {
return customerService;
} public void setCustomerService(CustomerService customerService) {
this.customerService = customerService;
} public String getId() {
return id;
} public void setId(String id) {
this.id = id;
}
public String findCustomerByid(){
System.out.println("查询用户的id:"+id);
customer = customerService.findById(Long.parseLong(id));
ActionContext.getContext().getValueStack().push(customer);
return "success";
} }
package customerServiceImpl; import customerDao.CustomerDao;
import customerService.CustomerService;
import domain.Customer; public class CustomerServiceImpl implements CustomerService{ private CustomerDao customerDao; public CustomerDao getCustomerDao() {
return customerDao;
} public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
} @Override
public Customer findById(Long id) {
// TODO Auto-generated method stub
Customer c = customerDao.findById(id);
return c;
} }
package customerDaoImpl; import org.hibernate.Session;
import org.hibernate.SessionFactory; import customerDao.CustomerDao;
import domain.Customer; public class CustomerImpl implements CustomerDao { private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public Customer findById(Long id) {
// TODO Auto-generated method stub
Session session = this.getSessionFactory().openSession();
Customer customer = session.get(Customer.class, id);
session.close();
return customer;
} }
<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>
<groupId>cn.xw.com</groupId>
<artifactId>sshpro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>sshpro</name>
<description>maven整合ssh</description> <!-- 属性 -->
<properties>
<spring.version>4.2.4.RELEASE</spring.version>
<hibernate.version>5.0.7.Final</hibernate.version>
<struts.version>2.3.24</struts.version>
</properties> <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>${struts.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 依赖管理 -->
<dependencies>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency> <!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
<scope>runtime</scope>
</dependency>
<!-- c3p0 --> <dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency> <!-- 导入 struts2 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency> <!-- servlet jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<!-- 日志 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<!-- jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies> <build>
<plugins>
<!-- 设置编译版本为1.7 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <!-- maven内置 的tomcat6插件 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<!-- 可以灵活配置工程路径 -->
<path>/ssh</path>
<!-- 可以灵活配置端口号 -->
<port>8080</port>
</configuration>
</plugin> </plugins>
</build> </project>
maven整合ssh框架笔记的更多相关文章
- Maven 整合SSH框架
1. 传递依赖冲突 1.1 传递依赖:A(项目)依赖B,B依赖C(1.1版本),B是A的直接依赖,C是A的传递依赖; A(项目)又依赖D,D依赖C(1.2版本),此时,C有两个版本,产生冲突; 1.2 ...
- maven学习记录三——maven整合ssh框架
6 整合ssh框架 6.1 依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar, 这种情况 叫 依赖传递 6.2 依赖版本冲突的解决 1. 第 ...
- Maven 整合 SSH 框架
前面的一系列文章中,我们总结了三大框架:Struts2,Hibernate,Spring 的基本知识.本篇就姑且尝试着使用 Maven 这个项目构建工具来将这三个框架整合一起.说到这里,如果有对 Ma ...
- 使用 IDEA和Maven 整合SSH框架
1.创建web工程 一路next 下去就行.完成后,IDEA会自动构建maven工程. 2.创建如下项目结构 需要将 java文件夹设置为SourcesRoot目录,否则无法创建package 设置操 ...
- Maven整合SSH框架的所有依赖和插件(记录下来,省的以后再写)
JDK:1.8 Tomcat:7 Maven:3.6.1 调了一个小时,终于没错误了,总结了一个规律,如果在用Tomcat插件启动项目时报错,显示如:org.apache.tomcat.util.bc ...
- Maven 整合SSH框架之pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 使用IDEA完成maven整合SSH框架时抛出Hibernate : Mapping (RESOURCE) not found
切入主题,看看今天的错误是如何发生的: 首先这是我的项目路径,java 是 Sources Root , resources 是 Resources Root ,放了所需要的配置文件,其中 Hiber ...
- Maven项目整合SSH框架
---------------------siwuxie095 Maven 项目整合 SSH 框架 创建 ...
- maven项目ssh框架的整合
1.环境 eclipse版本:Eclipse Mars2 4.5jdk版本:1.8maven版本:apache-maven 3.3.9zhnegs这是主要的开发工具版本,ssh的各种jar包版本就不列 ...
随机推荐
- Google advertiser api开发概述——入门指南
使用入门 AdWords API 可让应用直接与 AdWords 平台互动,大幅提高管理大型或复杂 AdWords 帐号和广告系列的效率.一些典型的用例包括: 自动帐号管理 自定义报告 基于产品目录的 ...
- Django2.1.3 smtp 邮件 553报警
用网易邮箱smtp发邮件时候一直报警553权限问题 smtplib.SMTPSenderRefused at: (553, b'Mail from must equal authorized user ...
- shiro框架
Shiro Shiro简介 SpringMVC整合Shiro,Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能. Authentication:身份认证/登录,验证用 ...
- angular2-4 之动效-animation
提示: angular2 时animation代码在核心模块里面(@angular/core里面);到了angular4.0时animation从核心模块中提取出来作为一个单独的模块, 这样可以在 ...
- ml交叉验证
https://blog.csdn.net/guanyuqiu/article/details/86006474 https://blog.csdn.net/weixin_42660173/artic ...
- yii2解决资源插件路径不对应问题
//本人ubuntu系统 composer self-update //升级到最新 //官网找到最新下面的这行执行. composer global require "fxp/compose ...
- 在win上配置linux虚拟机图解
首先,先下载安装vmware,cpu的类型不支持AMD. 一直点下一步完成安装.
- JAVA 创建文件和文件夹,删除文件和文件夹的实用工具
package com.file; import java.io.File; import java.io.IOException; //创建新文件和目录 public class CCRDFile ...
- 笨办法30Else 和 If
people = 30 cars = 40 trucks = 30 if cars < people: print "We should take the cars." el ...
- Linux中的#和$区别
[#]代表 root权限[$]代表普通用户