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

网站开发的实验心德/微信营销软件排行榜

网站开发的实验心德,微信营销软件排行榜,网站模板css,wordpress 首字母标签页mybatis学习篇:上次使用映射接口实现Mybatis,有不方便指出就是需要接口,且需要保证接口上不能存在其他的代理。这次通过SqlSessionTemplate基于模板类实现Mybatis,总的来说就是1.建立pojo类,sql映射文件,2.spring中装配…

mybatis学习篇:上次使用映射接口实现Mybatis,有不方便指出就是需要接口,且需要保证接口上不能存在其他的代理。这次通过SqlSessionTemplate基于模板类实现Mybatis,总的来说就是1.建立pojo类,sql映射文件,2.spring中装配,3.调用SqlSessionTemplate类访问数据库。这三个步骤:

一:sql映射文件
City.java

package com.suning.schema.mabatisInterface;  import java.io.Serializable;  public class City implements Serializable{  /** */  private static final long serialVersionUID = 1L;  private String provinceCode;  private String cityCode;  private String cityName;  public String getProvinceCode() {  return provinceCode;  }  public void setProvinceCode(String provinceCode) {  this.provinceCode = provinceCode;  }  public String getCityCode() {  return cityCode;  }  public void setCityCode(String cityCode) {  this.cityCode = cityCode;  }  public String getCityName() {  return cityName;  }  public void setCityName(String cityName) {  this.cityName = cityName;  }  
}  

sqlMap_city.xml:

<?xml version="1.0" encoding="UTF-8"?>    
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">    
<mapper namespace="city">    <select id="selectCity" parameterType="java.lang.String"  resultType="City">    SELECT   PROVINCE_CODE   AS   "provinceCode",  CITY_CODE       AS   "cityCode",  CITY_NAME       AS   "cityName"  FROM  PUMS_CITY  C  WHERE    C.CITY_CODE = #{cityCode}   </select>    
</mapper>  

定义命名空间namespace为city,sql的ID为selectCity,其中resultType="city",可以写全路径,也可以通过配置文件简写。
二:Spring中装配
sample-mybatis.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: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-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/context   http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/aop   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" >  <!--  autowised注解,注入Bean 等同 <context:component-scan base-package=”XX.XX”/>-->  <context:annotation-config />  <!-- 基于sqlSessionTemplate的mybatis配置 -->  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">    <property name="dataSource" ref="dataSource" />    <property name="configLocation" value="classpath:conf/spring/mybatisConfig.xml"/>  <property name="mapperLocations" value="classpath:conf/sqlMapMybatis/sqlMap_city.xml"/>  </bean>  <!-- sqlSessionTemplate配置 -->  <bean id="sqlSession"    class="org.mybatis.spring.SqlSessionTemplate">     <constructor-arg index="0" ref="sqlSessionFactory" />     </bean>    <bean id="mybatisService" class="com.suning.mybatis.MybatisService">  </bean>  
</beans>  

定义一个核心的SqlSessionFactoryBean实例,mybatis的核心管理类,通过dataSource指定数据源,configLocation代表mybatis的配置文件,mapperLocations指sql文件地址。注入SqlSessionTemplate的实例,构造方法初始化sqlSessionFactory。定义业务的实现类mybatisService

三:调用sqlSessionTemplate
MybatisService.Java:

package com.suning.mybatis;  import org.mybatis.spring.SqlSessionTemplate;  
import org.springframework.beans.factory.annotation.Autowired;  //mabitis测试的业务类  
public class MybatisService {  @Autowired  private SqlSessionTemplate sqlSessionTemplate;  //获取市详情  public City getCityDetail(String cityCode){  return (City)sqlSessionTemplate.selectOne("city.selectCity", cityCode);  }  
} 

通过自动注解,注入sqlSessionTemplate。city对应sql中命名空间,selectCity对应sql的ID,如图:

 

测试类MybatisMain.java  

package com.suning.mybatis;  import org.springframework.beans.factory.BeanFactory;  
import org.springframework.context.support.ClassPathXmlApplicationContext;  public class MybatisMain {  /** * 功能描述: <br> * 〈功能详细描述〉 *  * @param args * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */  public static void main(String[] args) {  BeanFactory factory = new ClassPathXmlApplicationContext(new String[] {  "classpath:conf/spring/sample-mybatis.xml", "classpath:conf/spring/sample-ds.xml" });  MybatisService test = (MybatisService) factory.getBean("mybatisService");  City cityDetail = (City) test.getCityDetail("560");  System.out.println("cityCode:560代表的城市为" + cityDetail.getCityName());  }  }  

 

http://www.jmfq.cn/news/4946059.html

相关文章:

  • 星巴克网站建设方案/google play谷歌商店
  • 做食品网站有哪些/太原模板建站定制网站
  • 怎么用虚拟主机做网站/网络营销工程师培训
  • 哪家网站推广做的好/一键优化清理
  • 2017优秀网站设计/网络营销的方法包括哪些
  • 网站建设开发流程按钮/百度人工
  • wordpress网站专题/深圳seo公司排名
  • 网站开发款计入什么科目/宁波网站推广排名
  • 小程序免费制作平台有吗/seo优化技术厂家
  • 计算机怎么建设网站/seo诊断书
  • 做农产品网站需要做的准备/关键词优化设计
  • 开源html5 网站模板/巨量算数关键词查询
  • 网站备案与域名备案/深圳网络推广案例
  • 做网站免费/河南做网站的
  • 什么网站免费做游戏/江北seo综合优化外包
  • 怎么用PS做网站横幅/热搜榜百度一下你就知道
  • wordpress怎样搭建外贸网站/seo实战密码第四版pdf
  • 免费做封面的网站/抖音搜索排名
  • 重庆建设集团官方网站/肇庆seo按天收费
  • 做网站一般注册商标哪个类/网址之家大全
  • 柳州住房和城乡建设部网站/良品铺子网络营销策划书
  • 临安网站设计/网站seo文章该怎么写
  • 惠州做网站的/百度搜索推广操作简要流程
  • 建设部网站官网 下载规范/品牌词优化
  • 宁波免费做网站/合肥建站公司seo
  • 网上做任务的网站有哪些/资阳市网站seo
  • 深圳做营销网站的公司简介/靖江seo要多少钱
  • 做导航网站用多大的空间/如何免费搭建自己的网站
  • 全国建设部网站/开源crm系统
  • 网站图片怎么做优化/nba录像回放