您的位置:首页 > 编程语言 > Java开发

springmvc+mybatis怎么传值到xml【转】

2016-09-26 18:24 274 查看
直接上代码首先是从程序的入口开始说: web.xml <?xmlversion="1.0"encoding="UTF-8"?> <web-appversion="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 设置session过期的时间 --> <session-config> <session-timeout>20</session-timeout> </session-config> <!-- 读取spring的配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/spring.xml;classpath:config/spring-myBatis.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <!-- 设置字符编码,将所有的字符编码同意设置为utf-8 --> <filter> <filter-name>filterEncoding</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> </filter> <filter-mapping> <filter-name>filterEncoding</filter-name> <url-pattern>/</url-pattern> </filter-mapping> <!-- 生成一次性验证码的servlet --> <servlet> <servlet-name>verifyCode</servlet-name> <servlet-class>com.longhang.tool.verifyCode.VerifyCodeServlet</servlet-class> </servlet> <!-- 将所有*.do的请求交给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:config/springMVC-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>verifyCode</servlet-name> <url-pattern>/verifyCode</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>DispatcherServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app> springMVC的配置文件 <?xmlversion="1.0"encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 配置自动扫描的包,让其扫描com.longhang,controller下面的所有包 --> <context:component-scanbase-package="com.longhang.controller"></context:component-scan> <!-- 配置视图解析器 将视图逻辑名解析为/*.jsp --> <beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"> <propertyname="prefix"value="/"></property> <propertyname="suffix"value=".jsp"></property> </bean> </beans> spring.xml的配置 <?xmlversion="1.0"encoding="UTF-8"?> <beansxmlns="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-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <context:property-placeholderlocation="classpath:config/druid.properties"/> <!--自动扫描(自动注入)--> <context:component-scanbase-package="com.longhang.service"></context:component-scan> </beans> spring-myBatis.xml配置 <?xmlversion="1.0"encoding="UTF-8"?> <beansxmlns="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-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 "> <!--配置数据源--><!-- <beanname="datasource"class="com.alibaba.druid.pool.DruidDataSource"init-method="init"destroy-method="close"> <propertyname="url"value="${jdbc_url}"></property> <propertyname="username"value="${jdbc_userName}"/> <propertyname="password"value="${jdbc_password}"/> </bean> --><beanname="datasource"class="com.alibaba.druid.pool.DruidDataSource"init-method="init"destroy-method="close"> <propertyname="url"value="jdbc:mysql://localhost:8000/bookShopping"></property> <propertyname="username"value="root"/> <propertyname="password"value="13072399672"/> </bean> <!--配置sqlSessionFactory并读取mybatis的一些配置--> <beanname="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean"> <propertyname="dataSource"ref="datasource"></property> <propertyname="mapperLocations"value="classpath:mapper/*.xml"/> </bean> <!-- 自动扫描将Mapper接口生成代理注入到Spring --> <beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer"> <propertyname="basePackage"value="com.longhang.dao"/> <propertyname="sqlSessionFactoryBeanName"value="sqlSessionFactory"/> </bean> <!-- 配置事物 --> <beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <propertyname="dataSource"ref="datasource"></property> </bean> <!-- <tx:annotation-driventransaction-manager="transactionManager"/> --> <!-- 事物的具体内容 --> <tx:adviceid="transactionAdvice"transaction-manager="transactionManager"> <tx:attributes> <tx:methodname="add*"propagation="REQUIRED"/> <tx:methodname="append*"propagation="REQUIRED"/> <tx:methodname="insert*"propagation="REQUIRED"/> <tx:methodname="save*"propagation="REQUIRED"/> <tx:methodname="update*"propagation="REQUIRED"/> <tx:methodname="modify*"propagation="REQUIRED"/> <tx:methodname="edit*"propagation="REQUIRED"/> <tx:methodname="delete*"propagation="REQUIRED"/> <tx:methodname="remove*"propagation="REQUIRED"/> <tx:methodname="repair"propagation="REQUIRED"/> <tx:methodname="delAndRepair"propagation="REQUIRED"/> <tx:methodname="get*"propagation="SUPPORTS"/> <tx:methodname="find*"propagation="SUPPORTS"/> <tx:methodname="load*"propagation="SUPPORTS"/> <tx:methodname="search*"propagation="SUPPORTS"/> <tx:methodname="datagrid*"propagation="SUPPORTS"/> <tx:methodname="*"propagation="SUPPORTS"/> </tx:attributes> </tx:advice> <!-- 定义一个切面,在定义的切面上加入事物 --> <aop:config> <aop:pointcutid="transactionPointcut"expression="execution(*com.longhang.service..*Impl.*(..))"/> <aop:advisorpointcut-ref="transactionPointcut"advice-ref="transactionAdvice"/> </aop:config> </beans> 关于mybatis的映射文件 <?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEmapperPUBLIC"-//mybatis.org//DTDMapper3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mappernamespace="com.longhang.dao.userDao.UserDao"> <resultMapid="baseResultMap"type="com.longhang.entity.user.User"> <idcolumn="uid"property="uid"jdbcType="CHAR"/> <resultcolumn="loginname"property="loginname"jdbcType="VARCHAR"/> <resultcolumn="loginpass"property="loginpass"jdbcType="VARCHAR"/> <resultcolumn="email"property="email"jdbcType="VARCHAR"/> <resultcolumn="status"property="status"jdbcType="VARCHAR"/> <resultcolumn="activationCode"property="activationCode"jdbcType="CHAR"/> </resultMap> <sqlid="base_column_list"> uid,loginname,loginpass,email,status,activationCode </sql> <!--根据id查询 返回的类型为User --> <selectid="findById"resultMap="baseResultMap"parameterType="java.lang.String"> select <includerefid="base_column_list"/> froml_user whereuid=#{uid,jdbcType=CHAR} </select> <!-- 根据activationCode查询 返回值是User --> <selectid="findByActivationCode"resultMap="baseResultMap"parameterType="java.lang.String"> select<includerefid="base_column_list"/> froml_user whereactivationCode=#{activationCode} </select> <!--

框架/平台构成:
Maven+Springmvc+Mybatis+Shiro(权限)+Tiles(模板)+ActiveMQ(消息队列)+Rest(服务)+WebService(服务)+EHcache(缓存)+Quartz(定时调度)+Html5(支持PC、IOS、Android)

用户权限系统:
组织结构:角色、用户、用户组、组织机构;权限点:页面、方法、按钮、数据权限、分级授权
项目管理新体验:
快速出原型系统、组件树、版本控制、模块移植、协同开发、实时监控、发布管理
可持续集成:
所有组件可移植、可定制、可扩充,开发成果不断积累,形成可持续发展的良性循环
支持平台平台:
WindowsXP、Windows7、Windows10、Linux、Unix
服务器容器:
Tomcat5/6/7、Jetty、JBoss、WebSphere8.5





















































































内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息