当前位置: 首页 > 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://wiki.neutronadmin.com/news/141621/

相关文章:

  • 网站建设对公司有什么好处邢台市最新人事调整
  • 做注册任务的网站有哪些四川建设行业数据共享平台网站问题
  • 无忧建站营销型网站概念
  • 网站开发确认函推广网页模板
  • 公众号做电影采集网站会被封做建材的网站有哪些
  • 网站左侧悬浮导航wordpress 权限修改
  • 鞍山市城乡建设局网站重庆品牌网站建设公司排名
  • 网站站欣赏电商公司名字大全
  • 手机移动网络屏蔽的网站网站制作:网推宝|百度
  • 如何做网站 代码做电影网站 需要进那些群
  • 成都科技网站建设咨询手机版网站建设
  • 网站开发协议合作网站建设分金手指排名十三
  • 产品型网站手游推广个人合作平台
  • python网站开发的优势成都网站建设服务有什么
  • 有哪个网站可以做ppt赚钱易网拓营销型网站
  • 河北省廊坊市建设银行网站大淘客网站怎么做
  • 外卖网站建设可行性分析照片编辑在线
  • 最新网站域名ip地址查询wordpress修改pageid
  • 网站一般如何做搜索功能手机怎么弄微信公众号
  • 男的和女的做那种事情网站做网站可以用中文域名备案嘛
  • 网站做二级域名干什么用大连住房和建设局网站
  • 网站建设技术知乎上海进出口贸易博览会
  • 建设一个网站需要什么硬件软件网络新闻专题做的最好的网站
  • 电子商务网站建设试验报告1wordpress安装云
  • 重庆网站快速优化排名上饶市建设局培训网站
  • 怎么制作网站开发设计wordpress模版文件夹
  • 西湖专业网站设计公司wordpress主题翻译
  • 做自己的网站有什么用广东企业网站seo哪家好
  • 如何做微信小程序网站2024年重大新闻简短
  • 洛阳建设银行官方网站长沙做网站建设价格