Jstl标签库
以下为可选 另外,若要使用mybatis逆向工程,需导入mybatis-generator-core-1.3.5.jar以及增加配置文件mbg.xml
<?xml version="1.0" enCoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBliC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration> <context ID="DB2tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 配置数据库连接 --> <jdbcConnection driverClass="com.MysqL.jdbc.Driver" connectionURL="jdbc:MysqL://localhost:3306/ssm_crud" userID="root" password="123"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 指定Javabean生成的位置 --> <javaModelGenerator targetPackage="com.fei.pojo" targetProject=".\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimstrings" value="true" /> </javaModelGenerator> <!-- 指定sql映射文件生成的位置 --> <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 指定mapper(dao)接口生成的位置 --> <javaClIEntGenerator type="XMLMAPPER" targetPackage="com.fei.mapper" targetProject=".\src\main\java"> <property name="enableSubPackages" value="true" /> </javaClIEntGenerator> <!-- 指定每个表的生成策略 --> <table tablename="tbl_emp" domainObjectname="Employee"></table> <table tablename="tbl_dept" domainObjectname="Department"></table> </context></generatorConfiguration>
还有核心主程序
package com.fei.test;import java.io.file;import java.util.ArrayList;import java.util.List;import org.mybatis.generator.API.MyBatisGenerator;import org.mybatis.generator.config.Configuration;import org.mybatis.generator.config.xml.ConfigurationParser;import org.mybatis.generator.internal.DefaultShellCallback;/** * mybatis代码生成主程序 * @Author xiaofei * @CreateDate 2019年9月2日 */public class MBGTest { public static voID main(String[] args) throws Exception { List<String> warnings = new ArrayList<String>(); boolean overwrite = true; file configfile = new file("mybatis-generator.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configfile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,callback,warnings); myBatisGenerator.generate(null); System.out.println("代码生成完毕!请查收"); }}若要使用分页插件,还需导入pageHelper-5.1.2.jar和jsqlparser-1.0.jar 若要使用文件上传还要另外导相关的包 2、整合思路 dao层 sqlMapConfig.xml,空文件即可,但是需要文件头 applicationContext-dao.xml 数据库连接池druID sqlSessionFactory对象,需要spring和mybatis整合包下的 配置mapper文件扫描器,Mapper动态代理开发增强版 service层 applicationContext-service.xml:配置包扫描器,扫描@service注解的组件类 applicationContext-tx.xml配置事务 web层 springmvc.xml:核心三大组件 web.xml:前端控制器、拦截器、编码过滤器等
也可以将dao层和service层的配置在一个文件中
下面是配置文件,我把dao层的applicationContext-dao.xml和applicationContext-service.xml写到一个配置文件spring-mybatis.xml中
3、配置文件编写 applicationContext.xml<?xml version="1.0" enCoding="UTF-8"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd "> <!-- spring的配置文件,这里主要配置业务和逻辑有关的配置,包括数据源,事务控制 --> <context:component-scan base-package="com.fei.service"> <!-- <context:exclude-filter type="annotation" Expression=" org.springframework.stereotype.Controller"/> --> </context:component-scan> <!-- ==================数据源的配置start================== --> <!-- 告诉spring让他去读取db.propertIEs配置文件 --> <context:property-placeholder location="classpath:db.propertIEs"/> <bean ID="dataSource" > <property name="driverClassname" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- ==================数据源的配置end================== --> <!-- ==============配置spring和mybatis的整合start============== --> <!-- MyBatis工厂 --> <bean ID="sqlSessionfactorybean" > <property name="dataSource" ref="dataSource"/> <!-- 指定mybatis核心配置文件的位置 --> <property name="configLocation" value="classpath:sqlMapConfig.xml"/> <!-- 指定mapper文件的位置 --> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!-- 配置扫描器,将mybatis接口的实现(一个代理对象)加入到ioc容器中,Mapper动态代理开发,扫描 --> <bean > <!-- 指定基本包,扫描所有mapper接口的实现,加入到ioc容器中 --> <property name="basePackage" value="com.fei.mapper"/> </bean> <!-- 配置一个可以执行批量 *** 作的sqlSession --> <bean ID="sqlSession" > <constructor-arg name="sqlSessionFactory" ref="sqlSessionfactorybean"/> <constructor-arg name="executorType" value="BATCH"/> </bean> <!-- ==============配置spring和mybatis的整合end============== --> <!-- ====================事务控制的配置start==================== --> <!-- 注解事务 --> <bean ID="transactionManager" > <!-- 控制住数据源里面连接的开启、关闭、回滚等 *** 作 --> <property name="dataSource" ref="dataSource"/> </bean> <!-- 1)开启基于注解的事务 --> <!-- <tx:annotation-driven transaction-manager="transactionManager"/> --> <!-- 2)开启基于xml配置的事务(比较重要的都是用配置形式) --> <aop:config> <!-- 切入点表达式 --> <aop:pointcut Expression="execution(* com.fei.service..*(..))" ID="txPoint"/> <!-- 配置事务增强 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/> </aop:config> <!-- 配置事务增强,事务如何切入 --> <tx:advice ID="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- 所有的方法都是事务方法 --> <tx:method name="*"/> <tx:method name="get*" read-only="true"/> </tx:attributes> </tx:advice> <!-- ====================事务控制的配置end==================== --> <!-- spring配置文件核心点(数据源,与mybatis的整合,事务控制) --> <!-- springmvc的异常处理器 --> <!-- <bean /> --></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"> <!-- springmvc的配置文件,主要包含网站跳转的逻辑控制 --> <!-- 配置controller扫描,精准扫描 --> <context:component-scan base-package="com.fei.controller" /> <!-- 定义视图文件解析器 --> <bean > <property name="prefix" value="/WEB-INF/Jsp/" /> <property name="suffix" value=".Jsp" /> </bean> <!-- 两个标准配置 --> <!-- 将springmvc不能处理的请求交给tomcat --> <mvc:default-servlet-handler/> <!-- 能支持一些springmvc更高级的一些功能,JSR303校验,快捷的AJAX...,映射动态请求 --> <mvc:annotation-driven/> <!-- ================ 上面是springmvc的基本配置 ================ --> <!-- 对静态资源放行 --> <!-- <mvc:resources location="/CSS/" mapPing="/CSS/**"/> <mvc:resources location="/Js/" mapPing="/Js/**"/> <mvc:resources location="/Fonts/" mapPing="/Fonts/**"/> <mvc:resources location="/img/" mapPing="/img/**"/> <mvc:resources location="/bower_components/" mapPing="/bower_components/**"/> <mvc:resources location="/dist/" mapPing="/dist/**"/> <mvc:resources location="/plugins/" mapPing="/plugins/**"/> --> <!-- 配置拦截器(多个) --> <!-- <mvc:interceptors> <mvc:interceptor> <mvc:mapPing path="/**"/> <mvc:exclude-mapPing path="/login"/> <mvc:exclude-mapPing path="/static/**"/> <bean /> </mvc:interceptor> </mvc:interceptors> --> <!-- 读取配置文件,解决硬编码问题 --> <!-- <context:property-placeholder location="classpath:code-params.propertIEs" /> --> </beans>db.propertIEs
jdbc.driver=com.MysqL.jdbc.Driverjdbc.url=jdbc:MysqL:///ssm_crud?useUnicode=true&characterEnCoding=UTF-8jdbc.username=rootjdbc.password=123sqlMapConfig.xml
<?xml version="1.0" enCoding="UTF-8" ?><!DOCTYPE configurationPUBliC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <!-- 配置别名,放置实体类 --> <typeAliases> <package name="com.fei.pojo"/> </typeAliases> <!-- pageHelper分页插件注册 --> <plugins> <plugin interceptor="com.github.pageHelper.PageInterceptor"> <!-- 分页参数合理化 --> <property name="resonable" value="true"/> </plugin> </plugins> </configuration>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" ID="WebApp_ID" version="2.5"> <!-- 1、启动spring容器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <Listener> <Listener-class>org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <!-- 2、springmvc的前端控制器,拦截所有请求 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 3、字符编码过滤器,一定要放在所有过滤器之前 --> <filter> <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>forceRequestEnCoding</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>forceResponseEnCoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapPing> <filter-name>CharacterEnCodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapPing> <!-- 4、使用Restful风格的URI,将页面普通的post请求转为指定的delete或put请求 --> <filter> <filter-name>HIDdenhttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HIDdenhttpMethodFilter</filter-class> </filter> <filter-mapPing> <filter-name>HIDdenhttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapPing> <!-- 处理直接发送put请求的过滤器 --> <filter> <filter-name>httpPutFormContentFilter</filter-name> <filter-class> org.springframework.web.filter.httpPutFormContentFilter</filter-class> </filter> <filter-mapPing> <filter-name>httpPutFormContentFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapPing></web-app>下面是项目的包结构以及lib目录 项目包结构 lib目录 总结
以上是内存溢出为你收集整理的SSM三大框架整合梳理全部内容,希望文章能够帮你解决SSM三大框架整合梳理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)