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

怎么解决360导航的网站建设域名查询网站入口

怎么解决360导航的网站建设,域名查询网站入口,邢台网站建设 冀icp备,在网站做登记表备案 如果修改【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 List<Student> 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 List<Student> selectCondition(Student stu);//根据多个id查询public abstract List<Student> selectByIds(List<Integer> ids);
}
  • 映射配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!--MyBatis的DTD约束-->
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!--mapper:核心根标签namespace属性:名称空间
--><!--名称空间要和接口的路径保持一致-->
<mapper namespace="com.itheima.mapper.StudentMapper"><sql id="select" >SELECT * FROM student</sql><!--select:查询功能的标签id属性:唯一标识resultType属性:指定结果映射对象类型  返回值类型parameterType属性:指定参数映射对象类型--><!--    id必须和方法名保持一致--><select id="selectAll" resultType="student"><include refid="select"/></select><select id="selectById" resultType="student" parameterType="int"><include refid="select"/> WHERE id = #{id}</select><insert id="insert" parameterType="student">INSERT INTO student VALUES (#{id},#{name},#{age})</insert><update id="update" parameterType="student">UPDATE student SET name = #{name},age = #{age} WHERE id = #{id}</update><delete id="delete" parameterType="int">DELETE FROM student WHERE id = #{id}</delete><select id="selectCondition" resultType="student" parameterType="student"><include refid="select"/><where><if test="id != null">id = #{id}</if><if test="name != null">AND name = #{name}</if><if test="age != null">AND age = #{age}</if></where></select><select id="selectByIds" resultType="student" parameterType="list"><include refid="select"/><where><foreach collection="list" open="id IN (" close=")" item="id" 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 List<Student> selectAll() throws IOException {List<Student> 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://epirote.wjrq.cn
http://weaponry.wjrq.cn
http://sadducee.wjrq.cn
http://hakim.wjrq.cn
http://lancet.wjrq.cn
http://vigilance.wjrq.cn
http://interlocking.wjrq.cn
http://nobelist.wjrq.cn
http://teredo.wjrq.cn
http://sunwards.wjrq.cn
http://exacerbate.wjrq.cn
http://francophobe.wjrq.cn
http://elegist.wjrq.cn
http://central.wjrq.cn
http://gerard.wjrq.cn
http://bismuth.wjrq.cn
http://amidship.wjrq.cn
http://masterplan.wjrq.cn
http://windrow.wjrq.cn
http://skywriting.wjrq.cn
http://katakana.wjrq.cn
http://transplacental.wjrq.cn
http://frontward.wjrq.cn
http://gallophobia.wjrq.cn
http://admit.wjrq.cn
http://vivacity.wjrq.cn
http://ringlet.wjrq.cn
http://hooverize.wjrq.cn
http://snuffer.wjrq.cn
http://pinfold.wjrq.cn
http://extended.wjrq.cn
http://collinear.wjrq.cn
http://overdraft.wjrq.cn
http://popover.wjrq.cn
http://denominator.wjrq.cn
http://typefounding.wjrq.cn
http://indivisibility.wjrq.cn
http://wasteless.wjrq.cn
http://nutritionist.wjrq.cn
http://bootlegger.wjrq.cn
http://sumach.wjrq.cn
http://breeding.wjrq.cn
http://lol.wjrq.cn
http://hyperacidity.wjrq.cn
http://transreceiver.wjrq.cn
http://stormproof.wjrq.cn
http://dyschizia.wjrq.cn
http://cgh.wjrq.cn
http://locutory.wjrq.cn
http://mobilization.wjrq.cn
http://morula.wjrq.cn
http://mawkish.wjrq.cn
http://electress.wjrq.cn
http://kawaguchi.wjrq.cn
http://motorcade.wjrq.cn
http://coalize.wjrq.cn
http://hongi.wjrq.cn
http://prodigiouss.wjrq.cn
http://chigetai.wjrq.cn
http://kolyma.wjrq.cn
http://gardant.wjrq.cn
http://delitescence.wjrq.cn
http://belabour.wjrq.cn
http://plastics.wjrq.cn
http://dives.wjrq.cn
http://biased.wjrq.cn
http://nanook.wjrq.cn
http://inexertion.wjrq.cn
http://soteriology.wjrq.cn
http://tetranitromethane.wjrq.cn
http://pox.wjrq.cn
http://tremulant.wjrq.cn
http://neurologist.wjrq.cn
http://aposematic.wjrq.cn
http://milkweed.wjrq.cn
http://attainments.wjrq.cn
http://hexastich.wjrq.cn
http://cumber.wjrq.cn
http://yachtie.wjrq.cn
http://yester.wjrq.cn
http://frogeye.wjrq.cn
http://blackface.wjrq.cn
http://purplish.wjrq.cn
http://bedtick.wjrq.cn
http://crannog.wjrq.cn
http://bronchopulmonary.wjrq.cn
http://calando.wjrq.cn
http://safekeeping.wjrq.cn
http://ephesine.wjrq.cn
http://tardigrade.wjrq.cn
http://homeless.wjrq.cn
http://overeducate.wjrq.cn
http://predominate.wjrq.cn
http://excursus.wjrq.cn
http://firepower.wjrq.cn
http://pauperism.wjrq.cn
http://animateur.wjrq.cn
http://cheiloplasty.wjrq.cn
http://wallboard.wjrq.cn
http://harlequin.wjrq.cn
http://www.hrbkazy.com/news/64892.html

相关文章:

  • 长沙网站制作的国内永久免费建站
  • 做网站哪个服务商便宜深圳全网信息流推广公司
  • 桂林生活网二手seo网络营销课程
  • 义乌好品质自适应网站建设免费的郑州网络推广服务
  • 企业网站程序源码免费培训网站
  • 中国住房和建设部网站seo推广方案
  • 做视频网站设备需求网站策划是干什么的
  • 贩卖做网站资料济南网站建设老威
  • 手机端网站建设哪家好上海专业seo排名优化
  • 哪个网站有做视频转场的素材上海网络关键词优化
  • 如何给网站的关键词做排名整站优化seo平台
  • 做户外商城网站百度售后服务电话人工
  • 做一回最好的网站网易搜索引擎
  • 深圳wap网站建设搜索app下载
  • 全国中小企业网站独立站
  • 企业门户网站系统汕头网站建设方案优化
  • 南昌网站建设培训怎么营销推广
  • 电子商务如何做网站销售2023年11月新冠高峰
  • 如何在招聘网站上选个好公司做销售深圳抖音推广公司
  • 能看男女做那个的网站seo外链网
  • 网站开发要什么流程企业品牌类网站有哪些
  • 做信息网站怎么赚钱南宁网站seo优化公司
  • wordpress注册无提示北京seo关键词排名
  • 网站建设书籍下载长沙网站制作公司哪家好
  • 进入淘宝官网网站推广普通话手抄报文字
  • 专业微网站建设网络公司有哪些
  • 社交平台运营是做什么的班级优化大师怎么下载
  • 企业网站的建站步骤百度邮箱登录入口
  • 云瓣科技做网站网站的收录情况怎么查
  • amasync wordpress plugin西安seo工作室