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

百度站长工具收费吗电商设计工作内容

百度站长工具收费吗,电商设计工作内容,做调像什么网站找活,网站首页排名没了MyBatis接口代理#xff1a; 采用 Mybatis 的代理开发方式实现 DAO 层的开发#xff0c;这种方式是目前的主流方式。Mapper 接口开发方法只需要程序员编写Mapper 接口#xff08;相当于Dao 接口#xff09;#xff0c;由Mybatis 框架根据接口定义创建接口的动态代理对象 采用 Mybatis 的代理开发方式实现 DAO 层的开发这种方式是目前的主流方式。Mapper 接口开发方法只需要程序员编写Mapper 接口相当于Dao 接口由Mybatis 框架根据接口定义创建接口的动态代理对象代理对象的方法体同上边Dao接口实现类方法。 Mapper接口开发需要遵循以下规范 映射配置文件中的namespace与mapper接口的类名相同映射配置文件中的增删改查标签的id属性要和Mappe接口中的方法名相同映射配置文件中的增删改查标签的parameterType属性要和Mappe接口中的方法参数相同映射配置文件中的增删改查标签的resultType属性要和Mappe接口中方法的返回值相同 接口代理原理 分析动态代理对象如何生成的 通过动态代理开发模式我们只编写一个接口不写实现类我们通过 getMapper() 方法最终获取到 org.apache.ibatis.binding.MapperProxy 代理对象然后执行功能而这个代理对象正是 MyBatis 使用了 JDK 的动态代理技术帮助我们生成了代理实现类对象。从而可以进行相关持久化操作。 分析方法是如何执行的 动态代理实现类对象在执行方法的时候最终调用了 mapperMethod.execute() 方法这个方法中通过 switch 语句根据操作类型来判断是新增、修改、删除、查询操作最后一步回到了 MyBatis 最原生的 SqlSession 方式来执行增删改查。 接口代理实现演示 编写StudentMapper接口 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); }Service接口 public interface StudentService {//查询全部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); }映射文件 ?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.mybatis.mapper.StudentMapper!--select查询功能的标签id属性唯一标识resultType属性指定结果映射对象类型parameterType属性指定参数映射对象类型--select idselectAll resultTypestudentSELECT * FROM student/selectselect idselectById resultTypestudent parameterTypeintSELECT * FROM student WHERE id #{id}/select!--对于增删改返回的都是影响行数所以resultType属性可以不写--insert 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}/delete /mapperService实现类 public class StudentMapperImpl implements StudentService {Overridepublic ListStudent selectAll() {ListStudent list null;SqlSession sqlSession null;InputStream rs null;try {// 加载核心配置文件rs Resources.getResourceAsStream(MybatisConfig.xml);// 获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(rs);// 获取SqlSession对象sqlSession build.openSession(true);// 获取接口实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法接收结果list mapper.selectAll();} catch (IOException e) {e.printStackTrace();} finally {// 释放资源SSif (sqlSession ! null) {sqlSession.close();}if (rs ! null) {try {rs.close();} catch (IOException e) {e.printStackTrace();}}}// 返回结果return list;}Overridepublic Student selectById(Integer id) {Student stu null;SqlSession sqlSession null;InputStream rs null;try {// 加载核心配置文件rs Resources.getResourceAsStream(MybatisConfig.xml);// 获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(rs);// 获取SqlSession对象sqlSession build.openSession(true);// 获取接口实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法接收结果stu mapper.selectById(id);} catch (IOException e) {e.printStackTrace();} finally {// 释放资源SSif (sqlSession ! null) {sqlSession.close();}if (rs ! null) {try {rs.close();} catch (IOException e) {e.printStackTrace();}}}return stu;}Overridepublic Integer insert(Student stu) {Integer result null;SqlSession sqlSession null;InputStream rs null;try {// 加载核心配置文件rs Resources.getResourceAsStream(MybatisConfig.xml);// 获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(rs);// 获取SqlSession对象sqlSession build.openSession(true);// 获取接口实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);// 通过实现类对象调用方法接收结果result mapper.insert(stu);} catch (IOException e) {e.printStackTrace();} finally {// 释放资源SSif (sqlSession ! null) {sqlSession.close();}if (rs ! null) {try {rs.close();} catch (IOException e) {e.printStackTrace();}}}return result;}Overridepublic Integer update(Student stu) {Integer result null;SqlSession sqlSession null;InputStream rs null;try {// 加载核心配置文件rs Resources.getResourceAsStream(MybatisConfig.xml);// 获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(rs);// 获取SqlSession对象sqlSession build.openSession(true);// 获取接口实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);result mapper.update(stu);} catch (IOException e) {e.printStackTrace();} finally {// 释放资源SSif (sqlSession ! null) {sqlSession.close();}if (rs ! null) {try {rs.close();} catch (IOException e) {e.printStackTrace();}}}return result;}Overridepublic Integer delete(Integer id) {Integer result null;SqlSession sqlSession null;InputStream rs null;try {// 加载核心配置文件rs Resources.getResourceAsStream(MybatisConfig.xml);// 获取工厂对象SqlSessionFactory build new SqlSessionFactoryBuilder().build(rs);// 获取SqlSession对象sqlSession build.openSession(true);// 获取接口实现类对象StudentMapper mapper sqlSession.getMapper(StudentMapper.class);result mapper.delete(id);} catch (IOException e) {e.printStackTrace();} finally {// 释放资源SSif (sqlSession ! null) {sqlSession.close();}if (rs ! null) {try {rs.close();} catch (IOException e) {e.printStackTrace();}}}return result;} }测试类 public class StuTest {// 创建业务层对象private StudentService service new StudentMapperImpl();//查询全部功能测试Testpublic void selectAll() {ListStudent students service.selectAll();for (Student stu : students) {System.out.println(stu);}}//根据id查询功能测试Testpublic void selectById() {Student stu service.selectById(3);System.out.println(stu);}//新增功能测试Testpublic void insert() {Student stu new Student(4,赵六,26);Integer result service.insert(stu);System.out.println(result);}//修改功能测试Testpublic void update() {Student stu new Student(4,赵六,16);Integer result service.update(stu);System.out.println(result);}//删除功能测试Testpublic void delete() {Integer result service.delete(4);System.out.println(result);} }
http://www.yutouwan.com/news/141621/

相关文章:

  • 网站开发安全模块方案jquery购物网站
  • 公司网站上传ftp教程福州全网网站建设
  • 手机上搭建个人网站网站建设的人才怎么称呼
  • 做网站找哪家公司网站多语言包
  • 怀化百度整站优化服务怎么做网站后端
  • 网站开发属于程序员吗php 建设网站
  • 如何更换网站域名吉林省建设厅官网查询
  • 建设做网站微信小程序制作公司
  • 江岸网站建设...无锡网站制作
  • 深圳做个网站要多少钱微信官方网站网址
  • 稻香村网站建设迅当网络外贸网站建设980
  • html5 素材网站网站和数字界面设计师
  • 提高网站排名的软件广安门内网站建设
  • 黄页网站推广app软件群晖搭建wordpress不加端口
  • dede网站源码企业网站推广哪些效果比较好
  • 没营业执照怎么做网站wordpress主题手机端
  • 百度网站排名查询虚拟机wordpress安装教程
  • 专门做淘宝客网站020网站开发
  • 如何用oss做视频网站软件工程培训机构学费
  • 网站栏目页排名怎样上传网站到百度
  • 做网站空间500m多少钱学习网站免费
  • c 网站开发构想前端是做网站吗
  • 做网站的公司怎么推广常州网站建设最易
  • 学校网站建设培训心得网站建设工作流程
  • php门户网站模板下载天津seo推广方法
  • seo教程技术整站优化专业网站建设必要性
  • 网站的建设方向湖北黄石网站建设
  • 建设文明网站包括广告公司推广软文
  • 特定ip段访问网站代码网站建设如何提高转化率
  • 小米路由做网站马鞍山 网站建设 有限公司