做个人网站,网站建设包括什么,做静态网站软件,运营推广的网站有哪些大家好#xff0c;我是雄雄#xff0c;今天来带着大家来配置一下SSM#xff08;springspringmvcmybatis#xff09;框架。01新建java web项目直接在myeclipse中#xff0c;新建一个web项目即可。02导入jar包将SSM所需的jar包复制到项目的/WebRoot/WEB-INF/lib中#xff0… 大家好我是雄雄今天来带着大家来配置一下SSMspringspringmvcmybatis框架。01新建java web项目直接在myeclipse中新建一个web项目即可。02导入jar包将SSM所需的jar包复制到项目的/WebRoot/WEB-INF/lib中在这里我整理了下大致需要34个jar文件复制完之后选中所有jar包右击—Build Path--Add to Build Path。03配置web.xml文件。web.xml文件需要配置三部分信息spring、springmvc以及解决springmvc传值乱码的过滤器分别如下spring配置信息listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenercontext-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:applicationContext.xml/param-value/context-paramspringmvc配置信息servletservlet-namespringmvc/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:springmvc-servlet.xml/param-value/init-paramload-on-startup1/load-on-startup/servletservlet-mappingservlet-namespringmvc/servlet-nameurl-pattern//url-pattern/servlet-mapping设置编码格式的过滤器信息!-- 解决springmvc传递值乱码问题 --filterfilter-nameencodingFilter/filter-namefilter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-classinit-paramparam-nameencoding/param-nameparam-valueutf-8/param-value/init-paraminit-paramparam-nameforceEncoding/param-nameparam-valuetrue/param-value/init-param/filterfilter-mappingfilter-nameencodingFilter/filter-nameurl-pattern/*/url-pattern/filter-mapping04配置Spring配置文件applicationContext.xml文件里面需要包含这些信息用来连接数据库的数据源信息!-- 配置数据源--bean iddataSource classorg.springframework.jdbc.datasource.DriverManagerDataSourceproperty namedriverClassName valuecom.mysql.jdbc.Driver/propertyproperty nameurl valuejdbc:mysql://localhost:3306/schooldb/propertyproperty nameusername valueroot/propertyproperty namepassword valueroot/property/bean加载mybatis-config.xml文件以及sql映射文件的SqlSessionFactory!--sqlSessionFactory --bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBeanproperty namedataSource refdataSource/propertyproperty nameconfigLocation valueclasspath:mybatis-config.xml/propertyproperty namemapperLocationslistvalueclasspath:org/dao/*.xml/value/list/property/beanMapper注入映射器的MapperScannerConfigurer!-- 配置自动映射器 --bean classorg.mybatis.spring.mapper.MapperScannerConfigurerproperty namebasePackage valueorg.dao/property/bean最后就是扫描注解的配置!-- 扫描所有注解信息 --context:component-scan base-packageorg.dao,org.service,org.web/mvc:annotation-driven/05配置springmvc的信息springmvc-servlet.xml中需要包含最基本的两个部分扫描注解和springmvc请求的前缀后缀设置!-- 扫描注解 --context:component-scan base-packageorg.web,org.dao,org.service/mvc:annotation-driven/!-- 配置前缀和后缀 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value//propertyproperty namesuffix value.jsp/property/bean06配置mybatis配置文件本文件简单点就配置个别名和打印sql语句就行都是可选的?xml version1.0 encodingUTF-8 ?
!DOCTYPE configurationPUBLIC -//mybatis.org//DTD Config 3.0//ENhttp://mybatis.org/dtd/mybatis-3-config.dtd
configurationsettings!-- 打印sql语句 --setting namelogImpl valueSTDOUT_LOGGING //settings!-- 起别名 --typeAliasespackage nameorg.entity//typeAliases/configuration附录spring配置文件applicationContext.xml?xml version1.0 encodingUTF-8?
beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:aophttp://www.springframework.org/schema/aopxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/p http://www.springframework.org/schema/p/spring-p-3.1.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd!-- 配置数据源--bean iddataSource classorg.springframework.jdbc.datasource.DriverManagerDataSourceproperty namedriverClassName valuecom.mysql.jdbc.Driver/propertyproperty nameurl valuejdbc:mysql://localhost:3306/schooldb/propertyproperty nameusername valueroot/propertyproperty namepassword valueroot/property/bean!--sqlSessionFactory --bean idsqlSessionFactory classorg.mybatis.spring.SqlSessionFactoryBeanproperty namedataSource refdataSource/propertyproperty nameconfigLocation valueclasspath:mybatis-config.xml/propertyproperty namemapperLocationslistvalueclasspath:org/dao/*.xml/value/list/property/bean!-- 配置自动映射器 --bean classorg.mybatis.spring.mapper.MapperScannerConfigurerproperty namebasePackage valueorg.dao/property/bean!-- 扫描所有注解信息 --context:component-scan base-packageorg.dao,org.service,org.web/mvc:annotation-driven//beansspringmvc配置文件springmvc-servlet.xml?xml version1.0 encodingUTF-8?
beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:aophttp://www.springframework.org/schema/aopxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/p http://www.springframework.org/schema/p/spring-p-3.1.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd!-- 扫描注解 --context:component-scan base-packageorg.web,org.dao,org.service/mvc:annotation-driven/!-- 配置前缀和后缀 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value//propertyproperty namesuffix value.jsp/property/bean/beansweb.xml文件?xml version1.0 encodingUTF-8?
web-app version3.0 xmlnshttp://java.sun.com/xml/ns/javaee xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsddisplay-name/display-name welcome-file-listwelcome-fileindex.jsp/welcome-file/welcome-file-list!-- springmvc的配置 --servletservlet-namespringmvc/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:springmvc-servlet.xml/param-value/init-paramload-on-startup1/load-on-startup/servletservlet-mappingservlet-namespringmvc/servlet-nameurl-pattern//url-pattern/servlet-mapping!-- spring --context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:applicationContext.xml/param-value/context-param!-- 监听配置 --listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener!-- 解决springmvc传递值乱码问题 --filterfilter-nameencodingFilter/filter-namefilter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-classinit-paramparam-nameencoding/param-nameparam-valueutf-8/param-value/init-paraminit-paramparam-nameforceEncoding/param-nameparam-valuetrue/param-value/init-param/filterfilter-mappingfilter-nameencodingFilter/filter-nameurl-pattern/*/url-pattern/filter-mapping/web-app配置到此结束明天带着大家实现一遍SSM的增删改查案例。独家特制纯手工辣椒酱小商店现在下单单件商品立减1.88元满80元减15元.往期精彩投资理财要趁早基金风险是最小2021-01-10 java中的泛型类型擦除2021-01-12 一百馒头一百僧大僧三个更无争小僧三人分一个大小和尚得几丁2021-01-09 你们好好的学回头教教我~2021-01-08 辣椒酱中奖说明~2021-01-07 点分享点点赞点在看