您的位置:首页 > 编程语言 > Java开发

S2SH整合以及图片上传(1)之spring搭建

2018-03-04 16:29 537 查看
    如若转载,请说明出处:http://blog.csdn.net/z1826378013/article/details/79437134
    相关jar包下载

    本套文章项目源码下载在本套文章的最后一篇文章结尾处:S2SH整合以及图片上传项目下载链接

    关于S2SH,主要是struts2+spring+hibernate开发。
    对于S2Sh整合开发来说,一个具体的操作流程,能够有效地解决一些由于粗心而造成的问题。

    此处我采用的流程是spring --> hibernate --> struts2.

    其中对应各个开发框架的版本为:spring4.3.14,hibernate4.3.11,struts2.3.32,mysql5.0.4。

    首先,我们先来搭建第一个框架,spring。

    第一步,在IDE开发环境中新建一个web项目,如下所示:

    


    第二步,在新建的web项目的/TestUpload/WebRoot/WEB-INF/lib目录中,粘贴如下图所示的spring的开发jar包:

    


    第三步,编写一个applicationContext.xml文件,放置到src目录下,其中的内容如下:<?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: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 -->

</beans>    第四步,在src目录下,新建一个测试用的包,在其中编写两个类,TestPojo以及TestSSH:
       


    TestPojo内容如下所示:
package com.ssh.test;

public class TestPojo {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
    TestSSH内容如下所示:package com.ssh.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSSH {

public static void main(String[] args) {

//获取applicationContext
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
TestPojo testPojo = (TestPojo) ac.getBean("testPojo");
System.out.println(testPojo.getName());

}

}
    接着要在applicationContext.xml中配置一个bean用来进行测试:<?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: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 -->
<bean id="testPojo" class="com.ssh.test.TestPojo">
    <property name="name" value="Test Spring" />
</bean>

</beans>    在上面配置的bean中,配置TestPojo的name属性的值为Test Spring,方便后续测试。
    第五步,测试spring,结果如下,则成功配置好了spring:

    


S2SH整合以及图片上传(2)之hibernate搭建(1)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ssh整合 图片上传