使用IDEA搭建SSM框架的项目
------------------------web.xml的配置文件-------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_4_0.xsd"
version="3.0">
<!--1配置监听器-->
<!--框架整合需要-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--2配置spring框架的配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<!--3对应spring mvc的servlet配置-->
<servlet>
<servlet-name>Dispatcherservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcherservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--字符集配置-->
<filte
r>
<filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
______________________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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
<property name="username" value="hsylx"/>
<property name="password" value="hsyhsy"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<property name="mapperLocations" value="classpath*:cn/smbms/dao/*.xml"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.smbms.dao"></property>
</bean>
</beans>
——————————————applicationContext-mvc.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<!--注解的包-->
<context:component-scan base-package="cn.smbms.controller,cn.smbms.service.impl"></context:component-scan>
<!--注解方式MVC-->
<mvc:annotation-driven/>
<!--视图解析器的类-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/static/"></property><!--所有页面从这个路径找-->
<property name="suffix" value=".html"></property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="4096000"></property>
<property name="defaultEncoding" value="utf-8"></property>
</bean>
<mvc:resources mapping="/static/images/**" location="/static/images/"></mvc:resources>
<mvc:resources mapping="/static/js/**" location="/static/js/"></mvc:resources>
<mvc:resources mapping="/static/css/**" location="/static/css/"></mvc:resources>
<mvc:resources mapping="/static/**" location="/static/"></mvc:resources>
</beans>
———————————————log4j.properties
—————————————————————
http://www.mybatis.org/mybatis-3/
log4j.rootLogger=DEBUG,CONSOLE,file
#log4j.rootLogger=ERROR,ROLLING_FILE
log4j.logger.cn.smbms.dao=debug
log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug
log4j.logger.java.sql.ResultSet=debug
log4j.logger.org.tuckey.web.filters.urlrewrite.UrlRewriteFilter=debug
######################################################################################
# Console Appender \u65e5\u5fd7\u5728\u63a7\u5236\u8f93\u51fa\u914d\u7f6e
######################################################################################
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=error
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern= [%p] %d %c - %m%n
######################################################################################
# DailyRolling File \u6bcf\u5929\u4ea7\u751f\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u683c\u5f0f:log2009-09-11
######################################################################################
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern=yyyy-MM-dd
log4j.appender.file.File=log.log
log4j.appender.file.Append=true
log4j.appender.file.Threshold=error
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-M-d HH:mm:ss}%x[%5p](%F:%L) %m%n
log4j.logger.com.opensymphony.xwork2=error
————————————目录————_————————
———————mapper映射———————
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.smbms.dao.SaleDao">
<resultMap type="cn.smbms.entity.Sale" id="SaleMap">
<result property="id" column="ID" jdbcType="OTHER"/>
<result property="price" column="PRICE" jdbcType="OTHER"/>
<result property="quantity" column="QUANTITY" jdbcType="OTHER"/>
<result property="totalprice" column="TOTALPRICE" jdbcType="OTHER"/>
<result property="saledate" column="SALEDATE" jdbcType="OTHER"/>
<result property="userid" column="USERID" jdbcType="OTHER"/>
<result property="productid" column="PRODUCTID" jdbcType="OTHER"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="SaleMap">
select
ID, PRICE, QUANTITY, TOTALPRICE, SALEDATE, USERID, PRODUCTID
from HSYLX.SALE
where ID = #{id}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="SaleMap">
select
ID, PRICE, QUANTITY, TOTALPRICE, SALEDATE, USERID, PRODUCTID
from HSYLX.SALE
limit #{offset}, #{limit}
</select>
<!--通过实体作为筛选条件查询-->
<select id="queryAll" resultMap="SaleMap">
select
ID, PRICE, QUANTITY, TOTALPRICE, SALEDATE, USERID, PRODUCTID
from HSYLX.SALE
<where>
<if test="id != null">
and ID = #{id}
</if>
<if test="price != null">
and PRICE = #{price}
</if>
<if test="quantity != null">
and QUANTITY = #{quantity}
</if>
<if test="totalprice != null">
and TOTALPRICE = #{totalprice}
</if>
<if test="saledate != null">
and SALEDATE = #{saledate}
</if>
<if test="userid != null">
and USERID = #{userid}
</if>
<if test="productid != null">
and PRODUCTID = #{productid}
</if>
</where>
</select>
<!--
何旭东
新增所有列(添加销售信息)
-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into HSYLX.SALE(ID,PRICE, QUANTITY, TOTALPRICE, SALEDATE, USERID, PRODUCTID)
values (S_sale.nextval,#{price}, #{quantity}, #{totalprice}, #{saledate}, #{userid}, #{productid})
</insert>
<!--通过主键修改数据-->
<update id="update">
update HSYLX.SALE
<set>
<if test="price != null">
PRICE = #{price},
</if>
<if test="quantity != null">
QUANTITY = #{quantity},
</if>
<if test="totalprice != null">
TOTALPRICE = #{totalprice},
</if>
<if test="saledate != null">
SALEDATE = #{saledate},
</if>
<if test="userid != null">
USERID = #{userid},
</if>
<if test="productid != null">
PRODUCTID = #{productid},
</if>
</set>
where ID = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from HSYLX.SALE where ID = #{id}
</delete>
——————
—————————dao———————————
public interface SaleDao {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
Sale queryById(Object id);
/**
* 查询指定行数据
*
* @param offset 查询起始位置
* @param limit 查询条数
* @return 对象列表
*/
List<Sale> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);
/**
* 通过实体作为筛选条件查询
*
* @param sale 实例对象
* @return 对象列表
*/
List<Sale> queryAll(Sale sale);
/**
* 新增数据(添加销售信息)
*何旭东
* @param sale 实例对象
* @return 影响行数
*/
int insert(Sale sale);
/**
* 修改数据
*
* @param sale 实例对象
* @return 影响行数
*/
int update(Sale sale);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Object id);