spring mvc系列文章 - springmvc spring mybatis ibatis freemark整合开发(2.0版:基于注解)

本文主要是介绍spring mvc系列文章 - springmvc spring mybatis ibatis freemark整合开发(2.0版:基于注解),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

基于注解的话,配置文件就简单多了,只需一个核心配置文件即可。


1 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"         xmlns:jdbc="http://www.springframework.org/schema/jdbc"         xmlns:context="http://www.springframework.org/schema/context"        xsi:schemaLocation="         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"        default-autowire="byName">  <!-- 引入配置文件    <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="location"><value>classpath:mysql.properties</value></property></bean>--><!--创建jdbc数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/test"/>  <property name="username" value="root"/><property name="password" value="jiaojun"/>  </bean>  <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  <property name="dataSource" ref="dataSource" />  </bean>  <!-- 创建SqlSessionFactory,同时指定数据源 -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  <!--<property name="configLocation" value="classpath:mybatis-config.xml" /> --> <property name="dataSource" ref="dataSource" />  </bean>  <!--以注解方式扫描Spring Bean --> <context:annotation-config /> <!--配置扫描SpringBean的时候 都需要扫描哪些目录下 --> <context:component-scan base-package="com.springmvc"></context:component-scan> <!-- 可通过注解控制事务 -->  <tx:annotation-driven />  <!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->  <!-- --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  <property name="basePackage" value="com.springmvc.dao" />  </bean> <!-- jsp视图配置 -->              <!--   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  <property name="prefix" value="/"/>  <property name="suffix" value=".jsp"/>  </bean>  --> <!-- freemarker视图解析配置 --><bean id="viewResolver"class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"><property name="cache" value="true" /><property name="prefix" value="" /><property name="suffix" value=".ftl" /><property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /><property name="contentType" value="text/html;charset=UTF-8"></property><property name="requestContextAttribute" value="request" /><property name="exposeSpringMacroHelpers" value="true" /><property name="exposeRequestAttributes" value="true" /><property name="exposeSessionAttributes" value="true" /></bean><!-- freemark初始化配置项 --><bean id="freemarkerConfig"class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"><property name="templateLoaderPath" value="/WEB-INF/template/" /><property name="freemarkerSettings"><props><!-- 如果模板不经常更新,此属性设置更新延迟时间 --><prop key="template_update_delay">60</prop><prop key="default_encoding">UTF-8</prop><prop key="number_format">#.###</prop><prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop><prop key="classic_compatible">true</prop><prop key="template_exception_handler">ignore</prop></props></property></bean></beans>  



源码下载地址: http://download.csdn.net/detail/sl0007/4496354

这篇关于spring mvc系列文章 - springmvc spring mybatis ibatis freemark整合开发(2.0版:基于注解)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/582920

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

mybatis的整体架构

mybatis的整体架构分为三层: 1.基础支持层 该层包括:数据源模块、事务管理模块、缓存模块、Binding模块、反射模块、类型转换模块、日志模块、资源加载模块、解析器模块 2.核心处理层 该层包括:配置解析、参数映射、SQL解析、SQL执行、结果集映射、插件 3.接口层 该层包括:SqlSession 基础支持层 该层保护mybatis的基础模块,它们为核心处理层提供了良好的支撑。

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

Hadoop企业开发案例调优场景

需求 (1)需求:从1G数据中,统计每个单词出现次数。服务器3台,每台配置4G内存,4核CPU,4线程。 (2)需求分析: 1G / 128m = 8个MapTask;1个ReduceTask;1个mrAppMaster 平均每个节点运行10个 / 3台 ≈ 3个任务(4    3    3) HDFS参数调优 (1)修改:hadoop-env.sh export HDFS_NAMENOD