项目简介
该项目主要是使用SSH开发Android后端服务器程序和前端App代码的实现,主要技术包含:
Android AsyncTask 、常见自定义控件、客户端高层类封装、Android HTTP通信、用户管理、购物流程、定位、二维码等知识点,希望大家跟踪查看最新的学习笔记。
数据库的创建
数据库使用的是MySQL5.6版本,脚本代码如下:
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`loginName` varchar(100) DEFAULT NULL,
`passowrd` varchar(64) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `cversion`;
CREATE TABLE `cversion` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`versionName` varchar(100) DEFAULT NULL,
`versionCode` int(11) DEFAULT NULL,
`updateDate` datetime DEFAULT NULL,
`downloadUrl` varchar(200) DEFAULT NULL,
`apkSize` varchar(100) DEFAULT NULL,
`apkName` varchar(200) DEFAULT NULL,
`updateLog` varchar(500) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`shopID` bigint(20) DEFAULT NULL,
`code` varchar(100) DEFAULT NULL,
`name` varchar(200) DEFAULT NULL,
`thumbnail` varchar(200) DEFAULT NULL,
`price` decimal(8,0) DEFAULT NULL,
`weight` decimal(8,0) DEFAULT NULL,
`color` varchar(100) DEFAULT NULL,
`factoryAddr` varchar(200) DEFAULT NULL,
`producer` varchar(200) DEFAULT NULL,
`productedDate` datetime DEFAULT NULL,
`RegisterDate` datetime DEFAULT NULL,
`IsHost` char(1) DEFAULT NULL COMMENT ‘1为促销商品;0为普通商品‘,
`describes` text,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `goodspic`;
CREATE TABLE `goodspic` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`shopID` bigint(20) DEFAULT NULL,
`picurl` varchar(200) DEFAULT NULL,
`linkurl` varchar(200) DEFAULT NULL,
`orders` int(11) DEFAULT NULL,
`status` char(1) DEFAULT NULL COMMENT ‘1为显示,0为隐藏‘,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `scanrecord`;
CREATE TABLE `scanrecord` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`userID` bigint(20) DEFAULT NULL,
`code` varchar(100) DEFAULT NULL,
`scanTime` datetime DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `shop`;
CREATE TABLE `shop` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(200) DEFAULT NULL,
`logo` varchar(200) DEFAULT NULL,
`phoneNum` char(20) DEFAULT NULL,
`addr` varchar(200) DEFAULT NULL,
`lngitude` double(9,6) DEFAULT NULL,
`latitude` double(9,6) DEFAULT NULL,
`type` char(1) DEFAULT NULL,
`describes` text,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`UserName` varchar(200) DEFAULT NULL,
`password` varchar(32) DEFAULT NULL,
`felling` varchar(200) DEFAULT NULL,
`head` varchar(200) DEFAULT NULL,
`regtime` datetime DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
DROP VIEW IF EXISTS `v_goods`;
CREATE ALGORITHM=UNDEFINED DEFINER=`videoadmin`@`` SQL SECURITY DEFINER VIEW `v_goods` AS select `goods`.`ID` AS `ID`,`goods`.`shopID` AS `shopID`,`goods`.`code` AS `code`,`goods`.`name` AS `goods_name`,`goods`.`thumbnail` AS `thumbnail`,`goods`.`price` AS `price`,`goods`.`weight` AS `weight`,`goods`.`color` AS `color`,`goods`.`factoryAddr` AS `factoryAddr`,`goods`.`producer` AS `producer`,`goods`.`productedDate` AS `productedDate`,`goods`.`RegisterDate` AS `RegisterDate`,`goods`.`IsHost` AS `IsHost`,`goods`.`describes` AS `goods_desc`,`shop`.`name` AS `shop_name`,`shop`.`logo` AS `logo`,`shop`.`phoneNum` AS `phoneNum`,`shop`.`addr` AS `addr`,`shop`.`lngitude` AS `lngitude`,`shop`.`latitude` AS `latitude`,`shop`.`type` AS `type`,`shop`.`describes` AS `shop_desc` from (`goods` join `shop`) where (`goods`.`shopID` = `shop`.`ID`);
创建数据库如下:
SSH环境搭建
我们使用“纯手工”的方式搭建自己的SSH环境
(1)创建一个Web Project(可以根据下边的图片建立工程)
注意:当我们创建config_struts、config_spring、config文件的时候一定要在文件上点击右键build path–use as sources folder
这样的话,在编译的时候才会把这三个配置文件加入到class目录中,否则会找不到。加入之后的话就像我上图中的一样和src是同级目录的,上边有一个package的图标的样式!
(2)配置文件的简单介绍:
log4j.properties
#
log4j.rootLogger=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
applicationContext.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 这一句话是允许加载properties配置文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${datasource.driverClassName}</value>
</property>
<property name="url">
<value>${datasource.url}</value>
</property>
<property name="username">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
</bean>
<!-- 配置sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<!-- <value>classpath:com/lc/igou/model</value> -->
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<!-- 缓存配置 -->
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
</props>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- <aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* com.lc.igou..*Services.*(..))"
id="myPointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
</aop:config> -->
</beans>
jdbc.properties
datasource.type=mysql
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/lcgou?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
datasource.username=root
datasource.password=1111
datasource.maxActive=100
datasource.maxIdle=2
datasource.maxWait=120000
datasource.whenExhaustedAction=1
datasource.validationQuery=select 1 from dual
datasource.testOnBorrow=true
datasource.testOnReturn=false
########################## c3p0 ############################
c3p0.acquireIncrement=3
c3p0.acquireRetryAttempts=30
c3p0.acquireRetryDelay=100
c3p0.initialPoolSize=3
c3p0.idleConnectionTestPeriod=900
c3p0.minPoolSize=2
c3p0.maxPoolSize=10
c3p0.maxStatements=0
c3p0.numHelperThreads=10
c3p0.maxIdleTime=30
##################### Hibernate ##################################
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.jdbc.batch_size=25
hibernate.jdbc.fetch_size=50
hibernate.show_sql=true
hibernate.connection.release_mode=after_transaction
hibernate.format_sql=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
struts.properties
#struts.custom.i18n.resources=messageResource
struts.i18n.encoding=UTF-8
struts.objectFactory.spring.useClassCache = true
struts.multipart.parser=jakarta
struts.multipart.saveDir=
struts.multipart.maxSize=2097152
struts.serve.static=true
struts.serve.static.browserCache=true
struts.enable.DynamicMethodInvocation = true
struts.enable.SlashesInActionNames = false
struts.tag.altSyntax=true
struts.devMode = false
struts.i18n.reload=false
struts.ui.theme=xhtml
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
struts.url.includeParams = get
struts.dispatcher.parametersWorkaround = false
struts.freemarker.templatesCache=false
struts.freemarker.wrapper.altMap=true
struts.xslt.nocache=false
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="df" extends="struts-default">
<action name="userlogin" class="userAction" method="login" />
</package>
<package name="goods" extends="struts-default">
<action name="findgoods" class="goodsAction" method="findGoods" />
<action name="findGoodsByCode" class="goodsAction" method="findGoodsByCode" />
</package>
<package name="version" extends="struts-default">
<action name="update" class="versionAction" method="updateVersion" />
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 项目的ID -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>iGouServer.root</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<!-- 日志配置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<!-- 监听器配置 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 内存管理,防止内存溢出 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- filter配置 struts的配置 -->
<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>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!-- 编码方式的配置 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 欢迎首页配置 -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
上边的配置文件,了解SSH的应该都比较清楚,不过多解释,都有注释
(3)关于使用Hibernate,因为我们没有在项目中进行直接的逆向,而是使用jar直接导入的,那么我们就可以童工另一个项目HibernateImport 通过hibernate的逆向工程生成model,然后再复制到自己的项目文件下
原项目环境初步搭建代码地址: 链接:http://pan.baidu.com/s/1jGh8crs 密码:y5go
后续内容持续更新!
时间: 2024-10-14 11:36:12