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

苏州市城乡和建设局网站首页南通高端网站设计建设

苏州市城乡和建设局网站首页,南通高端网站设计建设,wordpress百度主动不推送了,成功营销网站【Java闭关修炼】MyBatis-接口代理的方式实现Dao层实现规则代码实现代理对象分析接口代理方式小结实现规则 映射配置文件中的名称空间必须和Dao层接口的全类名相同映射配置文件的增删改查标签的id属性必须和Dao层接口方法的参数相同映射配置文件中的增删改查标签的parameterTyp… 【Java闭关修炼】MyBatis-接口代理的方式实现Dao层实现规则代码实现代理对象分析接口代理方式小结实现规则 映射配置文件中的名称空间必须和Dao层接口的全类名相同映射配置文件的增删改查标签的id属性必须和Dao层接口方法的参数相同映射配置文件中的增删改查标签的parameterType属性必须和Dao层接口方法的参数相同映射配置文件中的增删改查标签中的resultType属性必须和Dao层接口方法的返回值相同 代码实现 删除mapper层接口的实现类 修改映射配置文件 修改service层接口的实现类 采用接口代理方式实现功能 mapper层接口 package com.itheima.mapper;import com.itheima.bean.Student;import java.util.List;/*持久层接口*/// 接口的名称要和namespace一样 public interface StudentMapper {//查询全部public abstract ListStudent selectAll();//根据id查询public abstract Student selectById(Integer id);//新增数据public abstract Integer insert(Student stu);//修改数据public abstract Integer update(Student stu);//删除数据public abstract Integer delete(Integer id);//多条件查询public abstract ListStudent selectCondition(Student stu);//根据多个id查询public abstract ListStudent selectByIds(ListInteger ids); } 映射配置文件 ?xml version1.0 encodingUTF-8 ? !--MyBatis的DTD约束-- !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd!--mapper核心根标签namespace属性名称空间 --!--名称空间要和接口的路径保持一致-- mapper namespacecom.itheima.mapper.StudentMappersql idselect SELECT * FROM student/sql!--select查询功能的标签id属性唯一标识resultType属性指定结果映射对象类型 返回值类型parameterType属性指定参数映射对象类型--!-- id必须和方法名保持一致--select idselectAll resultTypestudentinclude refidselect//selectselect idselectById resultTypestudent parameterTypeintinclude refidselect/ WHERE id #{id}/selectinsert idinsert parameterTypestudentINSERT INTO student VALUES (#{id},#{name},#{age})/insertupdate idupdate parameterTypestudentUPDATE student SET name #{name},age #{age} WHERE id #{id}/updatedelete iddelete parameterTypeintDELETE FROM student WHERE id #{id}/deleteselect idselectCondition resultTypestudent parameterTypestudentinclude refidselect/whereif testid ! nullid #{id}/ifif testname ! nullAND name #{name}/ifif testage ! nullAND age #{age}/if/where/selectselect idselectByIds resultTypestudent parameterTypelistinclude refidselect/whereforeach collectionlist openid IN ( close) itemid separator,#{id}/foreach/where/select /mapper StudentServiceImpl package com.itheima.service.impl;import com.itheima.bean.Student; import com.itheima.mapper.StudentMapper; import com.itheima.service.StudentService; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException; import java.io.InputStream; import java.util.List; /*业务层实现类*/ public class StudentServiceImpl implements StudentService {Overridepublic ListStudent selectAll() throws IOException {ListStudent students null;SqlSession sqlSession null;InputStream is null;// 没有了持久层实现对象 只有持久层的接口try{// 加载核心配置文件is Resources.getResourceAsStream(MyBatisConfig.xml);// 返回一个字节输入流对象// 获取sqlSession工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(is);// 通过工厂对象获取SqlSession对象sqlSession build.openSession(true);// 代表自动提交事务// 获取StudentMapper接口的实现类对象// 父类的接口指向实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法 接受结果students mapper.selectAll();// 释放资源// 返回结果}catch(Exception e){e.printStackTrace();}finally {// 释放资源if(sqlSession ! null){sqlSession.close();}if(is ! null){is.close();}}// 返回结果return students;}Overridepublic Student selectById(Integer id) throws IOException {// 根据id来查询对象Student stu null;SqlSession sqlSession null;InputStream is null;try{// 加载核心配置文件is Resources.getResourceAsStream(MyBatisConfig.xml);//获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(is);// 通过工厂对象获取SqlSessionsqlSession build.openSession(true);// 代表自动提交事务// 获取StudentMapper接口的实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法 接受结果stu mapper.selectById(id);// 获取学生对象}catch (Exception e){e.printStackTrace();}finally {if(sqlSession ! null){sqlSession.close();}if(is ! null){is.close();}}// 获取学生对象return stu;}// 新增学生对象Overridepublic Integer insert(Student stu) throws IOException {// 根据id来查询对象Integer result null;SqlSession sqlSession null;InputStream is null;try{// 加载核心配置文件is Resources.getResourceAsStream(MyBatisConfig.xml);//获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(is);// 通过工厂对象获取SqlSessionsqlSession build.openSession(true);// 代表自动提交事务// 获取StudentMapper接口的实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法 接受结果result mapper.insert(stu);// 返回影响的行数}catch (Exception e){e.printStackTrace();}finally {if(sqlSession ! null){sqlSession.close();}if(is ! null){is.close();}}// 获取学生对象return result;}Overridepublic Integer update(Student stu) throws IOException {// 根据id来查询对象Integer result null;SqlSession sqlSession null;InputStream is null;try{// 加载核心配置文件is Resources.getResourceAsStream(MyBatisConfig.xml);//获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(is);// 通过工厂对象获取SqlSessionsqlSession build.openSession(true);// 代表自动提交事务// 获取StudentMapper接口的实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法 接受结果result mapper.update(stu);// 返回影响的行数}catch (Exception e){e.printStackTrace();}finally {if(sqlSession ! null){sqlSession.close();}if(is ! null){is.close();}}// 获取学生对象return result;}Overridepublic Integer delete(Integer id) throws IOException {// 根据id来查询对象Integer result null;SqlSession sqlSession null;InputStream is null;try{// 加载核心配置文件is Resources.getResourceAsStream(MyBatisConfig.xml);//获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(is);// 通过工厂对象获取SqlSessionsqlSession build.openSession(true);// 代表自动提交事务// 获取StudentMapper接口的实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法 接受结果result mapper.delete(id);// 返回影响的行数}catch (Exception e){e.printStackTrace();}finally {if(sqlSession ! null){sqlSession.close();}if(is ! null){is.close();}}// 获取学生对象return result;} } 代理对象分析 接口代理方式小结 接口代理方式可以让我们之编写接口即可而实现类对象由MyBatis生成 实现规则 映射配置文件中的名称空间必须和Dao层接口的全类名相同映射配置文件中的增删改查标签的id属性必须和Dao层接口的方法名相同映射配置文件中的增删改查标签的parameterType属性必须和Dao层接口方法的参数相同映射配置文件中的增删改查标签的resultType属性必须和Dao层接口方法的返回值相同 获取动态代理对象 SqlSession功能类中的getMapper()方法
http://www.dnsts.com.cn/news/218281.html

相关文章:

  • 海葵音乐制作公司qq群排名优化软件购买
  • 宁夏交通建设质监局官方网站网页设计作业要求
  • 手机网站免费建设不封号的电销系统
  • 企业网站建设方案有那些外贸网站建设推广费用
  • 网站建设企业排名推广国家商标查询入口
  • 可以做机械设计接单的网站宿州建设网站公司
  • 江门网站seo优化怎么样建设一个电影网站
  • 广州网页制作网站维护湖南二维码标签报价
  • 网站如何做交互网站维护的主要内容包括
  • 做电商网站要多少钱小程序公司有必要做吗
  • 个人备案网站可以做商城吗研发项目管理系统
  • 一般建一个外贸网站多少钱怎么在别人网站做跳转
  • 建设厅网站官网百度做公司网站多少钱
  • 博客登陆wordpress上海如何优化网站
  • 做网站宁波明星网站建设
  • 阿里云虚拟主机可以做几个网站福州百度快速优化
  • 网站开发怎么找客户怎样建网站买东西
  • 仿冒网站制作哈尔滨网站建设科技公司
  • 单页网站修改浅析社区网站的建设
  • 横岗网站设计外贸公司网站如何免费推广
  • 做网站建设有前景吗注册高级工程师
  • 可以在公司局域网做网站吗网站怎么描述
  • 怎样提高网站的流量可以做mv 的视频网站
  • 佛山家居网站全网营销做剧情游戏的网站
  • 营销 推广 网站企业网站建设指导思想
  • 网站开发可以用两种语言吗seo优化主要做什么
  • 福建省建设工程职业注册网站怎么做提卡密网站
  • 网站打开空白页面做展厅的网站
  • 公司网站首页怎么制作wordpress页头图片比例
  • 韩国优秀网站欣赏wordpress文章添加媒体缩略图