ssm框架模板

ssm框架:
16个依赖:junit/spring-webmvc/spring-jdbc/mybatis/mybatis-spring/druid/mysql
servlet-api/jsp-api/jstl/lombok/log4j/jackson-databind/aspectjweaver/aspectjrt/pagehelper
在这里插入图片描述
5个net.wanho:controller/service/mapper/filter/pojo
5个resoruces:mybatis/spring/resource/log4j/net.wanho.mapper
web.xml:spring:contextConfigLocation/springMvc:dispatcherServlet/乱码过滤器:characterEncodingFilter
resources:mybatis
在这里插入图片描述
net.wanho.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="net.wanho.mapper.StudentMapper">
    <insert id="insert">
        insert into students VALUES (null,#{sname},#{sage},#{saddress},#{sgender},#{classId},null)

</insert>
<update id="update">
    update students
    <set>
        <if test="#{sname}!=null">
            sname=#{sname},
        </if>
        <if test="#{sage}!=null">
            sage=#{sage},
        </if>
        <if test="#{saddress}!=null">
            saddress=#{saddress},
        </if>
        <if test="#{sgender}!=null">
            sgender=#{sgender},
        </if>
        <if test="#{classId}!=null">
            classId=#{classId},
        </if>

    </set>
    where sid=#{sid}

</update>

<select id="findAll" resultType="Student">
    SELECT * from students
</select>
<cache
    eviction="FIFO"
    flushInterval="60000"
    size="512"
    readOnly="true"
/>

<delete id="deleteStudent">
    delete from students where sid=#{sid}
</delete>
<delete id="deleteStudentScore">
     delete from student_score where sid=#{sid}
</delete>

<select id="queryById" resultType="Student">

     select st.sid,st.sname,st.sgender,st.sage,st.saddress,st.classId,sc.scoreName,c.className from students  st LEFT JOIN student_score ss on st.sid = ss.sid LEFT JOIN score sc on ss.score_id = sc.score_id LEFT JOIN stuclass c on c.classId = st.classId where st.sid = #{sid}
</select>
<select id="queryClass" resultType="StuClass">
    select c.* from stuclass c
</select>
<select id="queryScore" resultType="Score">
    select sc.score_id scoreId, sc.scoreName scoreName from  score sc
</select>


</mapper>

jdbc.properties:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/java130
jdbc.username=root
jdbc.password=root

application-dao.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:context="http://www.springframework.org/schema/context"
       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">

<!--读取配置文件-->
<context:property-placeholder location="classpath:resource/jdbc.properties"></context:property-placeholder>

<!--数据源-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="username" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
</bean>

<!--mybatis-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis/mybatis_config.xml"></property>
    <property name="dataSource" ref="dataSource"></property>
</bean>

<!--配置扫描:交给spring-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="net.wanho.mapper"></property>
</bean>
application-service.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:context="http://www.springframework.org/schema/context"
       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">

<!--扫包-->
<context:component-scan base-package="net.wanho.service"></context:component-scan>

</beans>

apptication-trans.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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<!--事务-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" value="dataSource"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="insert*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="add*" propagation="REQUIRED"/>
        <tx:method name="query*" propagation="SUPPORTS"/>
        <tx:method name="find*" propagation="SUPPORTS"/>
        <tx:method name="get*" propagation="SUPPORTS"/>
    </tx:attributes>
</tx:advice>
<aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* net.wanho.service..*.*(..))"></aop:advisor>
</aop:config>
</beans>

springmvc.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: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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.alibaba.com/schema/stat http://www.alibaba.com/schema/stat.xsd">

<!--扫包-->
<context:component-scan base-package="net.wanho.controller"></context:component-scan>

<!--适配器+映射器-->
<mvc:annotation-driven></mvc:annotation-driven>


<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

<!--静态资源-->
<mvc:default-servlet-handler></mvc:default-servlet-handler>

<!--多媒体解析器-->

<!--拦截器-->

<!--异常-->
</beans>

log4j.properties:

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=/wanheweb_project2wydt.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=debug,stdout,file

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

  <display-name>Archetype Created Web Application</display-name>
  <!--spring:contextConfigLocation-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/application-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!--springMvc:dispatcherServlet-->
  <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:spring/springmvc.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>

  <!--乱码过滤器:characterEncodingFilter-->
  <filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>net.wanho.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


</web-app>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值