当前位置: 首页 > news >正文

深圳哪家公司做网站沈阳媒体

深圳哪家公司做网站,沈阳媒体,沈阳网页设计专业,asp企业网站源码下载​ mybatis整合 主要是处理dao包下的接口和xml文件&#xff0c;以及service下的类和接口 第一步 在resource目录下创建mybatis-config.xml文件【注意点&#xff1a;mybatis-config.xml文件下通常都是写别名、和mappers】 <?xml version"1.0" encoding"U…


mybatis整合

主要是处理dao包下的接口和xml文件,以及service下的类和接口

第一步

在resource目录下创建mybatis-config.xml文件【注意点:mybatis-config.xml文件下通常都是写别名、和mappers】

<?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><typeAlias type="com.pojo.Books" alias="books"/></typeAliases><mappers><mapper class="com.dao.BooksMapper"/></mappers>
</configuration>

第二步:

dao和service包下的文件

dao包

public interface BooksMapper {int add(Books books);int delete(int bookID);int update(Books books);Books selectById(int bookID);List<Books> selectAll();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.BooksMapper"><insert id="add" parameterType="books">insert into books(bookID,bookName,bookCount,detail) values (#{bookID},#{bookName},#{bookCount},#{detail})</insert><delete id="delete" parameterType="int">delete from books where bookID=#{bookID}</delete><update id="update" parameterType="books">update books set bookName=#{bookName},bookCount=#{bookCount},detail=#{detail} where bookID=#{bookID}</update><select id="selectById" resultType="books">select * from books where bookID=#{bookID};</select><select id="selectAll" resultType="books">select * from books</select>
</mapper>

service包

public interface BooksService {int add(Books books);int delete(int bookID);int update(Books books);Books selectById(int bookID);List<Books> selectAll();
}
public class BooksServiceImpl implements BooksService {private BooksMapper booksMapper;public void setBooksMapper(BooksMapper booksMapper) {this.booksMapper = booksMapper;}public int add(Books books) {return booksMapper.add(books);}public int delete(int bookID) {return booksMapper.delete(bookID);}public int update(Books books) {return booksMapper.update(books);}public Books selectById(int bookID) {return booksMapper.selectById(bookID);}public List<Books> selectAll() {return booksMapper.selectAll();}
}

【注意点:这里的serviceImpl别忘了给它set注入】

第三步:

最后需要在总的spring.xml文件中导入包

<import resource="classpath:spring-dao.xml"/>

spring整合

第一步:

配置整合mybatis
关联数据库文件

<context:property-placeholder location="classpath:database.properties"/>

数据库连接池

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><!-- 配置连接池属性 --><property name="driverClass" value="${jdbc.driver}"/><property name="jdbcUrl" value="${jdbc.url}"/><property name="user" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/><!-- c3p0连接池的私有属性 --><property name="maxPoolSize" value="30"/><property name="minPoolSize" value="10"/><!-- 关闭连接后不自动commit --><property name="autoCommitOnClose" value="false"/><!-- 获取连接超时时间 --><property name="checkoutTimeout" value="10000"/><!-- 当获取连接失败重试次数 --><property name="acquireRetryAttempts" value="2"/></bean>

配置SqlSessionFactory对象

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
注入数据库连接池
<property name="dataSource" ref="dataSource"/>

配置MyBaties全局配置文件:mybatis-config.xml

<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- 3.配置SqlSessionFactory对象 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 注入数据库连接池 --><property name="dataSource" ref="dataSource"/><!-- 配置MyBaties全局配置文件:mybatis-config.xml --><property name="configLocation" value="classpath:mybatis-config.xml"/></bean>

配置扫描Dao接口包,动态实现Dao接口注入到spring容器中

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 注入sqlSessionFactory --><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/><!-- 给出需要扫描Dao接口包 --><property name="basePackage" value="com.dao"/></bean>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><!--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:applicationContext.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><!--encodingFilter--><filter><filter-name>encodingFilter</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>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--Session过期时间--><session-config><session-timeout>15</session-timeout></session-config></web-app>

spring-mvc.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 配置SpringMVC --><!-- 1.开启SpringMVC注解驱动 --><mvc:annotation-driven/><!-- 2.静态资源默认servlet配置--><mvc:default-servlet-handler/><!-- 3.配置jsp 显示ViewResolver视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/><property name="prefix" value="/WEB-INF/jsp/"/><property name="suffix" value=".jsp"/></bean><!-- 4.扫描web相关的bean --><context:component-scan base-package="com.controller" />
</beans>

http://www.yayakq.cn/news/201428/

相关文章:

  • 简述营销型网站推广的方法wordpress同步到新浪微博
  • 网站免费正能量直接进入在线网上购物的网站开发背景
  • 重庆网站建设重庆网站建设公司网站建设下载天马行市民云app
  • 做网站必须用对方服务器百度指数指的是什么
  • 网站建设酷隆自己做的网站怎么放视频教程
  • 谁做网站做网站兼容性怎么设置
  • 门户网站开发难点微信公众号内嵌网站开发
  • 电子商务网站的规划与建设论文网站分哪几种
  • 网站开发常用的数据库深圳专业做网站
  • 网站建设情况彩票网站的推荐怎么做
  • 做爰试看的网站百度互联网营销
  • 旅游企业网站建设湖南做网站的公司
  • 房山富阳网站建设小程序解决方案网页模板下载
  • 做缓网站wordpress 即将跳转
  • 外贸营销网站制作公司做那个类型的网站赚钱
  • 织梦网站密码wordpress 3.1 下载
  • 昆明专业网站营销邯郸房产网签查询网
  • 网站源码上传完后怎么做百度认证怎么认证
  • 电子网站建设价格网上注册公司需要什么材料和手续
  • 百度抓取不到网站优质专业建设方案
  • 网站的标题可以改吗神箭手wordpress
  • 爱站网爱情电影网怎样才能创建网站
  • 北京手机网站建设报价网站开发相关技术发展
  • 烟台网站建设技术支持东莞网络推广哪家公司好
  • 网站代码是多少贵州网站备案查询
  • 网站建设和网站搭建哪个好无锡本地模板网站建设产品
  • 江华网站建设飞享套餐
  • 广州网站建设公司哪家比较好冰雪蜜城店加盟费多少
  • 建设部监理工程师报名网站什么是产品网络推广
  • 电子商务网站建设大作业内蒙古建设兵团网站