<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.0modelVersion>
<groupId>com.qytxgroupId>
<artifactId>architecturelartifactId>
<version>0.0.1-SNAPSHOTversion>
<packaging>pompackaging>
<modules>
<module>architecturelwebmodule>
<module>commonmodule>
<module>customermgrmodule>
<module>goodsmgrmodule>
<module>goodsmgrwebmodule>
<module>cartmgrmodule>
<module>ordermgrmodule>
<module>storemgrmodule>
modules>
<dependencies>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelperartifactId>
<version>4.1.4version>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>servlet-apiartifactId>
<version>2.5version>
<scope>providedscope>
dependency>
<dependency>
<groupId>cglibgroupId>
<artifactId>cglibartifactId>
<version>3.1version>
<exclusions>
<exclusion>
<artifactId>asmartifactId>
<groupId>org.ow2.asmgroupId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>asmgroupId>
<artifactId>asmartifactId>
<version>3.3.1version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.aspectjgroupId>
<artifactId>aspectjweaverartifactId>
<version>1.7.4version>
dependency>
<dependency>
<groupId>org.aspectjgroupId>
<artifactId>aspectjrtartifactId>
<version>1.7.4version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druidartifactId>
<version>1.0.29version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatis-springartifactId>
<version>1.3.0version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatisartifactId>
<version>3.4.1version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-jdbcartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-txartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-ormartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-context-supportartifactId>
<version>4.0.0.RELEASEversion>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-log4j12artifactId>
<version>1.7.5version>
<exclusions>
<exclusion>
<artifactId>slf4j-apiartifactId>
<groupId>org.slf4jgroupId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>ch.qos.logbackgroupId>
<artifactId>logback-classicartifactId>
<version>1.0.13version>
<scope>testscope>
<exclusions>
<exclusion>
<artifactId>slf4j-apiartifactId>
<groupId>org.slf4jgroupId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.28version>
dependency>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.11version>
<scope>testscope>
dependency>
<dependency>
<groupId>jstlgroupId>
<artifactId>jstlartifactId>
<version>1.2version>
dependency>
<dependency>
<groupId>taglibsgroupId>
<artifactId>standardartifactId>
<version>1.1.2version>
dependency>
dependencies>
project>
<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.0modelVersion>
<parent>
<groupId>com.qytxgroupId>
<artifactId>architecturelartifactId>
<version>0.0.1-SNAPSHOTversion>
parent>
<artifactId>customermgrartifactId>
<packaging>warpackaging>
<dependencies>
<dependency>
<groupId>com.qytxgroupId>
<artifactId>commonartifactId>
<version>0.0.1-SNAPSHOTversion>
dependency>
dependencies>
<build>
<resources>
<resource>
<directory>src/main/resourcesdirectory>
<includes>
<include>**/*.propertiesinclude>
<include>**/*.xmlinclude>
<include>**/*.tldinclude>
includes>
<filtering>truefiltering>
resource>
<resource>
<directory>src/main/javadirectory>
<includes>
<include>**/*.javainclude>
<include>**/*.xmlinclude>
includes>
<filtering>truefiltering>
resource>
resources>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-resources-pluginartifactId>
<version>2.6version>
<configuration>
<encoding>UTF-8encoding>
configuration>
plugin>
<plugin>
<groupId>org.eclipse.jettygroupId>
<artifactId>jetty-maven-pluginartifactId>
<version>9.2.8.v20150217version>
<configuration>
<stopKey>shutdownstopKey>
<stopPort>9966stopPort>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>9999port>
<maxIdleTime>60000maxIdleTime>
connector>
<scanIntervalSeconds>2scanIntervalSeconds>
<requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
<filename>target/access-yyyy_mm_dd.logfilename>
<filenameDateFormat>yyyy_MM_ddfilenameDateFormat>
<logDateFormat>yyyy-MM-dd HH:mm:sslogDateFormat>
<logTimeZone>GMT+8:00logTimeZone>
<append>trueappend>
<logServer>truelogServer>
<retainDays>120retainDays>
<logCookies>truelogCookies>
requestLog>
<webApp>
<contextPath>/customercontextPath>
webApp>
configuration>
plugin>
plugins>
build>
project>
jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/arch1?useUnicode=true&characterEncodeing=UTF-8
jdbc.username=root
jdbc.password=root
applicationContext.xml
<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:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">
<context:property-placeholder location="classpath:jdbc.properties" />
<context:component-scan base-package="com.qytx.architecturel.customermgr.service.imp">context:component-scan>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="1" />
<property name="minIdle" value="1" />
<property name="maxActive" value="10" />
bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml">property>
bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.qytx.architecturel.customermgr.dao">property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
bean>
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource">property>
bean>
<tx:annotation-driven transaction-manager="txManager" />
beans>
mybatis-config.xml (个人感觉mybatis配置文件就是起个别名,指定mapper文件用的,还有用到分页插件、配置拦截器,改变sql)
<configuration>
<typeAliases>
<typeAlias type="com.qytx.architecturel.customermgr.vo.CustomerModel" alias="CM"/>
<typeAlias type="com.qytx.architecturel.customermgr.vo.CustomerQueryModel" alias="CQM"/>
typeAliases>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<property name="dialect" value="mysql"/>
plugin>
plugins>
<mappers>
<mapper resource="com/qytx/architecturel/customermgr/dao/mapper/CustomerDaoMapper.xml" />
mappers>
configuration>
spring-mvc.xml 最简单的配置
<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:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">
<context:component-scan base-package="com.qytx.architecturel.customermgr.action"/>
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
bean>
beans>
CustomerDaoMapper.xml
<mapper namespace="com.qytx.architecturel.customermgr.dao.CustomerDao">
<insert id="create" parameterType="CM">
insert into tb_customer(customerId,pwd,showName,trueName,registerTime)
values(#{customerId},#{pwd},#{showName},#{trueName},#{registerTime})
insert>
<update id="update" parameterType="CM">
update tb_customer set customerId=#{customerId},pwd=#{pwd},showName=#{showName},trueName=#{trueName},registerTime=#{registerTime}
where uuid=#{uuid}
update>
<select id="delete" parameterType="int">
delete from tb_customer where uuid=#{uuid}
select>
<select id="getByUuid" parameterType="int" resultType="CM">
select * from tb_customer where uuid=#{uuid}
select>
<select id="getByCondition" parameterType="CQM" resultType="CM">
select * from tb_customer
<where>
<if test="uuid!=null && uuid>0">
and uuid = #{uuid}
if>
<if test="customerId!=null">
and customerId like concat('%',#{customerId} ,'%')
if>
<if test="showName!=null ">
and showName like concat('%',#{showName} ,'%')
if>
where>
select>
mapper>
在公共包写的。其他类只需继承就可以
BaseDao
package com.qytx.common.dao;
import java.util.List;
public interface BaseDao {
public void create(E cm);
public void update(E cm);
public void delete(int uuid);
public E getByUuid(int uuid);
public List getByCondition(QE qe);
}
CustomerDao
package com.qytx.architecturel.customermgr.dao;
import org.springframework.stereotype.Repository;
import com.qytx.architecturel.customermgr.vo.CustomerModel;
import com.qytx.architecturel.customermgr.vo.CustomerQueryModel;
import com.qytx.common.dao.BaseDao;
@Repository
public interface CustomerDao extends BaseDao{
}
BaseService
package com.qytx.common.service;
import com.github.pagehelper.PageInfo;
public interface BaseService {
public void create(E cm);
public void update(E cm);
public void delete(int uuid);
public E getByUuid(int uuid);
public PageInfo getByCondition(QE qe);
}
BaseServiceImpl
这个需要特别说明一下,这里的实现serviceimp需要他的继承类来提供dao,因为basedao是不可能在spring中的。这点一定要记住,还有,注解是写在实现类上的。
package com.qytx.common.service;
import com.github.pagehelper.PageInfo;
import com.qytx.common.dao.BaseDao;
public class BaseServiceImpl implements BaseService{
private BaseDao baseDao;
public void setBaseDao(BaseDao baseDao) {
this.baseDao = baseDao;
}
@Override
public void create(E cm) {
// TODO Auto-generated method stub
baseDao.create(cm);
}
@Override
public void update(E cm) {
// TODO Auto-generated method stub
baseDao.update(cm);
}
@Override
public void delete(int uuid) {
// TODO Auto-generated method stub
baseDao.delete(uuid);
}
@Override
public E getByUuid(int uuid) {
// TODO Auto-generated method stub
return baseDao.getByUuid(uuid);
}
@Override
public PageInfo getByCondition(QE qe) {
// TODO Auto-generated method stub
return new PageInfo(baseDao.getByCondition(qe));
}
}
CustomerService
package com.qytx.architecturel.customermgr.service;
import com.qytx.architecturel.customermgr.vo.CustomerModel;
import com.qytx.architecturel.customermgr.vo.CustomerQueryModel;
import com.qytx.common.service.BaseService;
public interface CustomerService extends BaseService{
}
CustomerServiceImpl
package com.qytx.architecturel.customermgr.service.imp;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.qytx.architecturel.customermgr.dao.CustomerDao;
import com.qytx.architecturel.customermgr.service.CustomerService;
import com.qytx.architecturel.customermgr.vo.CustomerModel;
import com.qytx.architecturel.customermgr.vo.CustomerQueryModel;
import com.qytx.common.service.BaseServiceImpl;
@Service(value="customerService")
public class CustomerServiceImpl extends BaseServiceImpl implements CustomerService{
private CustomerDao customerDao=null;
@Resource
public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
super.setBaseDao(customerDao);
}
}
CustomerModel
package com.qytx.architecturel.customermgr.vo;
import java.io.Serializable;
public class CustomerModel implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer uuid;
private String customerId;
private String pwd;
private String showName;
private String trueName;
private String registerTime;
public Integer getUuid() {
return uuid;
}
public void setUuid(Integer uuid) {
this.uuid = uuid;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getShowName() {
return showName;
}
public void setShowName(String showName) {
this.showName = showName;
}
public String getTrueName() {
return trueName;
}
public void setTrueName(String trueName) {
this.trueName = trueName;
}
public String getRegisterTime() {
return registerTime;
}
public void setRegisterTime(String registerTime) {
this.registerTime = registerTime;
}
@Override
public String toString() {
return "CustomerModel [uuid=" + uuid + ", customerId=" + customerId
+ ", pwd=" + pwd + ", showName=" + showName + ", trueName="
+ trueName + ", registerTime=" + registerTime + "]";
}
public CustomerModel(Integer uuid, String customerId, String pwd,
String showName, String trueName, String registerTime) {
super();
this.uuid = uuid;
this.customerId = customerId;
this.pwd = pwd;
this.showName = showName;
this.trueName = trueName;
this.registerTime = registerTime;
}
public CustomerModel() {
super();
// TODO Auto-generated constructor stub
}
}
CustomerQueryModel 专为customer提供的查询类
package com.qytx.architecturel.customermgr.vo;
import java.io.Serializable;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
public class CustomerQueryModel extends CustomerModel{
private PageHelper pageHelper=new PageHelper();
public PageHelper getPageHelper() {
return pageHelper;
}
public void setPageHelper(PageHelper pageHelper) {
this.pageHelper = pageHelper;
}
}