吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6664|回复: 13
收起左侧

[Java 转载] 【第一帖】java 搭建SSM项目 并且测试效果

[复制链接]
高手寂寞 发表于 2017-3-1 20:47
自己是2011年注册的 发现还是最低的等级 有点受不了了 关键居然有人把帖子权限设置20 我都进不去了  让我很难堪啊~
好了 不扯那么多了
开始 首先 我的工具、环境是 jdk7 tomcat7、eclipse、Maven

1.创建Maven项目
1.jpg
2.jpg

2.数据创建表 创建数据
4.jpg

3.这是项目路径
6.jpg

4.pom.xml
[Java] 纯文本查看 复制代码
<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/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.test</groupId>
	<artifactId>Pojie</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>Pojie Maven Webapp</name>
	<url>http://maven.apache.org</url>

	<properties>
		<spring.version>4.1.7.RELEASE</spring.version>
		<mybatis.version>3.3.0</mybatis.version>
		<mybatis-spring.version>1.2.3</mybatis-spring.version>
		<mysql.version>5.1.36</mysql.version>
		<servlet.version>3.1.0</servlet.version>
		<json-lib.version>2.4</json-lib.version>
		<jackson.version>2.5.2</jackson.version>
		<cedec.version>1.10</cedec.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>c3p0</groupId>
			<artifactId>c3p0</artifactId>
			<version>0.9.1.2</version>
		</dependency>

		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>${cedec.version}</version>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
			<version>${jackson.version}</version>
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>${jackson.version}</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>${mybatis.version}</version>
		</dependency>

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>${mysql.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</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-jdbc</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>${mybatis-spring.version}</version>
		</dependency>

		<!-- 添加Servlet支持 -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>${servlet.version}</version>
		</dependency>

		<dependency>
			<groupId>net.sf.json-lib</groupId>
			<artifactId>json-lib</artifactId>
			<version>${json-lib.version}</version>
			<classifier>jdk15</classifier>
		</dependency>

	</dependencies>


	<build>
		<finalName>Pojie</finalName>
	</build>
</project>


applicationContext.xml
[Java] 纯文本查看 复制代码
<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

	<!-- 配置数据源 -->
		<!-- 数据库配置 -->
	<bean id="properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location" value="classpath:jdbc.properties" />
	</bean>

	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<property name="driverClass" value="${Driver}" />
		<property name="jdbcUrl" value="${URL}" />
		<property name="user" value="${UserName}" />
		<property name="password" value="${Password}" />
		<property name="maxPoolSize" value="${MaxPoolSize}" />
		<property name="minPoolSize" value="${MinPoolSize}" />
		<property name="initialPoolSize" value="${InitialPoolSize}" />
		<property name="maxStatements" value="${MaxStatements}" />
		<property name="maxIdleTime" value="${MaxIdleTime}" />
		<property name="idleConnectionTestPeriod" value="${IdleConnectionTest}" />
		<property name="preferredTestQuery" value="${TestQuery}" />
		
		<property name="testConnectionOnCheckin" value="false"/>
    	<property name="testConnectionOnCheckout" value="true"/>
	</bean>
	
	<!-- 配置mybatis的sqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- 自动扫描mappers.xml文件 -->
		<property name="mapperLocations" value="classpath:com/test/mapping/*.xml"></property>
	</bean>

	<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.test.dao" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
	</bean>

	<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 配置事务通知属性 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<!-- 定义事务传播属性 -->
		<tx:attributes>
			<tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="remove*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="submit*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="modify*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
			<tx:method name="get*" propagation="NOT_SUPPORTED" read-only="true"/>
			<tx:method name="*" propagation="SUPPORTS" read-only="true" rollback-for="java.lang.Exception" />
		</tx:attributes>
	</tx:advice>

	<!-- 配置事务切面 -->
	<aop:config>
		<aop:pointcut id="serviceOperation"
			expression="execution(* com.test.service.*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
	</aop:config>


</beans>


spring-mvc.xml
[Java] 纯文本查看 复制代码
<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

	<!-- 自动扫描的包名 -->
	<mvc:annotation-driven />
	<context:annotation-config />
	<!-- 使用注解的包,包括子集 -->
	<context:component-scan base-package="com.test.*" />

</beans>  


jdbc.properties
[Java] 纯文本查看 复制代码
UserName=cx
Password=cx
URL=jdbc:mysql://192.168.1.254:3306/db_pojie?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
Driver=com.mysql.jdbc.Driver
MaxPoolSize=60
MinPoolSize=3
InitialPoolSize=10
MaxStatements=50
MaxIdleTime=60
IdleConnectionTest=3600
TestQuery=SELECT 1 FROM DUAL


5.controller层
QQ截图20170301203051.jpg

service 接口
s.jpg

service 接口实现类
sl.jpg

dao层
d.jpg

最后sql
sql.jpg

最后看下效果:
5.jpg

浏览器已经 接收到我们的信息了 包括业务层加的字也有了!


然后目前自己也没想好做什么 做一步看一步吧  最后做成什么
大家给我点个赞哈!
还有我的英语1级都没有.....我不是大牛 我只是个基层工作者!
强烈鄙视公司没啥事还加班的 ,好无聊!





代码:链接: https://pan.baidu.com/s/1eStDKMA 密码: e3fe

免费评分

参与人数 6吾爱币 +6 热心值 +6 收起 理由
小学森 + 1 + 1 已答复!
关谷神奇的小号 + 1 这种配置最烦了,试试去掉struts加上jpa不需要写实现类了
loooooooong + 1 + 1 打过一次ssm框架,不过失败了
花开丶依然爱 + 2 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
zhangjy_12 + 1 + 1 谢谢@Thanks!
qq7156792 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

VioletKiss 发表于 2017-3-14 22:54
正在学SSM,不过楼主,为什么不用HikariCP这个数据库连接池,听说这个连接池很强啊,现在在跟着别人做项目,也是用的C3P0,看来还是老牌的好吗?
雪寂霜凝 发表于 2017-3-1 21:18
厉害咯,自学的吗?SSM,我现在都是SM而已,还不会Spring整合,有空互相交流,我也是学java的,扣扣530597773,备注52pojie就知道了,哈哈
 楼主| 高手寂寞 发表于 2017-3-1 20:48
amscracker 发表于 2017-3-1 21:02
不觉明历啊!真有功夫折腾
当红灬依赖 发表于 2017-3-1 21:03
小白来摩拜
dxdeng 发表于 2017-3-1 21:12
我连SSm是啥都不懂啊
对味 发表于 2017-3-1 21:13
感谢分享,羡慕学习的动力的毅力!
qlcyl110 发表于 2017-3-1 21:22
老大厉害1支持您!!!
herofkk 发表于 2017-3-1 22:05
不觉明历啊!真有功夫折腾呀。。。呵呵
我是萌萌哒提莫 发表于 2017-3-1 22:20
你这个注解凶哦,自己看看有没得不足的?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-27 03:49

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表