首页 > 其他分享 >mapper层

mapper层

时间:2023-06-10 11:45:01浏览次数:52  
标签:mapper like courseid where select stuid condition

AnswerMapper.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="com.example.academicadministration.dao.AnswerDao">
<insert id="addAnswer" parameterType="com.example.academicadministration.pojo.Answer">
    insert into answer (stuid, homeworkid, score, answerfile, submittime)
    VALUES(#{stuid},#{homeworkid},#{score},#{answerfile},#{submittime})
</insert>
    <update id="updateAnswer" parameterType="com.example.academicadministration.pojo.Answer">
        update answer set answerfile=#{answerfile},submittime=#{submittime} where stuid=#{stuid} and homeworkid=#{homeworkid}
    </update>
    <select id="myAnswer" resultType="com.example.academicadministration.pojo.Answer">
        select * from answer where stuid=#{stuid} and homeworkid=#{homeworkid}
    </select>
    <update id="updateScore" parameterType="com.example.academicadministration.pojo.Answer">
        update answer set score=#{score} where stuid=#{stuid} and homeworkid=#{homeworkid}
    </update>
    <delete id="deleteAnswer">
        delete from answer where stuid=#{stuid} and homeworkid=#{homeworkid}
    </delete>
</mapper>

CourseMapper.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="com.example.academicadministration.dao.CourseDao">
    <insert id="addCourse" parameterType="com.example.academicadministration.pojo.Course">
        insert into course
(coursename, courselimit, courseday, coursetime, courseroom, coursekind)
values (#{coursename},#{courselimit},#{courseday},#{coursetime},#{courseroom},#{coursekind})
    </insert>
    <delete id="deleteCourse">
        delete from course where courseid=#{courseid}
    </delete>

    <select id="browseCourse" resultType="com.example.academicadministration.pojo.Course">
        select * from course where courseid like #{condition} or courseroom like #{condition} or coursetime like #{condition} or courseday like #{condition} or coursekind like #{condition} or coursename like #{condition} or courselimit like #{condition} or coursenumber like #{condition}
    </select>
    <select id="checkTeacher" resultType="java.lang.String">
        select teaid from teacourse where courseid=#{courseid} and teaid=#{teaid}
    </select>
    <insert id="addTeacherCourse">
        insert ignore  into teacourse (teaid, courseid) values (#{teaid},#{courseid})
    </insert>
    <delete id="deleteTeacherCourse">
        delete from teacourse where teaid=#{stuid} and courseid=#{courseid}
    </delete>
    <insert id="addStudentCourse">
        insert ignore into stucourse (stuid, courseid) values (#{stuid},#{courseid})
    </insert>
    <update id="addNum">
        update course set coursenumber=coursenumber+1 where courseid=#{courseid}
    </update>
    <delete id="deleteStudentCourse">
        delete from stucourse where stuid=#{stuid} and courseid=#{courseid}
    </delete>
    <update id="deleteNum">
        update course set coursenumber=coursenumber-1 where courseid=#{courseid}
    </update>
    <select id="myCourse" resultType="com.example.academicadministration.pojo.Course">
        select * from course where courseid in (select courseid from stucourse where stuid=#{stuid})
    </select>
    <select id="TmyCourse" resultType="com.example.academicadministration.pojo.Course">
        select * from course where courseid in (select courseid from teacourse where teaid=#{teaid})
    </select>
    <select id="browseScore" resultType="java.lang.String">
        select coursescore from stucourse where stuid=#{stuid} and courseid=#{courseid}
    </select>
    <update id="updateScore">
        update stucourse set coursescore=#{coursescore} where stuid=#{stuid} and courseid=#{courseid}
    </update>
</mapper>

HomeworkMapper.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="com.example.academicadministration.dao.HomeworkDao">
<insert id="addHomework" parameterType="com.example.academicadministration.pojo.Homework">
    insert into homework (courseid, startline, endline, homeworkrequest, homeworkfile)
    VALUES(#{courseid},#{startline},#{endline},#{homeworkrequest},#{homeworkfile})
</insert>
    <delete id="deleteHomework">
        delete from homework where homeworkid=#{homeworkid}
    </delete>
    <select id="browseHomeworkAll" resultType="com.example.academicadministration.pojo.Homework">
        select * from homework where courseid = #{courseid}
    </select>
    <select id="browseHomework1" resultType="com.example.academicadministration.pojo.Homework">
        select * from homework where endline &lt;= (select curdate()) and  courseid =#{courseid}
    </select>
    <select id="browseHomework2" resultType="com.example.academicadministration.pojo.Homework">
        select * from homework where endline &gt; (select curdate()) and  courseid =#{courseid}
    </select>
</mapper>

MangerMapper.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="com.example.academicadministration.dao.MangerDao">
<select id="login" resultType="java.lang.String">
    select mangerpwd from manger where mangerid=#{id}
</select>
    <update id="reset">
        update manger set mangerpwd=MD5(#{newpwd}) where mangerid=#{mangerid} and MD5(mangerpwd=#{oldpwd})
    </update>
</mapper>

StudentMapper.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="com.example.academicadministration.dao.StudentDao">
    <insert id="addStudent" parameterType="com.example.academicadministration.pojo.Student">
        insert ignore into student
            (stuid, stupwd, stuname, stusex, sturace, stuorigin, stuenrollment, stucollege, stumajor, stuclass, stuphone, stuphoto)
        VALUES(#{stuid},MD5(#{stupwd}),#{stuname},#{stusex},#{sturace},#{stuorigin},#{stuenrollment},#{stucollege},#{stumajor},#{stuclass},#{stuphone},#{stuphoto})
    </insert>
    <delete id="deleteStudent">
        delete from student where stuid=#{stuid}
    </delete>
    <update id="inauditStudent">
        update student set stustate=false where stuid=#{stuid}
    </update>
    <update id="auditStudent">
        update student set stustate=true where stuid=#{stuid}
    </update>
    <update id="reset">
        update student set stupwd=MD5(#{newpwd}) where stuid=#{stuid} and stupwd=#{stupwd}
    </update>
    <select id="browseStudent" resultType="com.example.academicadministration.pojo.Student">
        select * from student where stuid like #{condition} or stusex like #{condition} or stuclass like #{condition} or stuorigin like #{condition}
or sturace like #{condition} or stucollege like #{condition} or stuenrollment like #{condition} or stumajor like #{condition} or stuname like #{condition}
or stuphone like #{condition}
    </select>
    <select id="myStudent" resultType="com.example.academicadministration.pojo.Student">
        select * from student where stuid in (select stuid from stucourse where courseid=#{courseid})
    </select>
</mapper>

TeacherMapper.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="com.example.academicadministration.dao.TeacherDao">
    <insert id="addTeacher" parameterType="com.example.academicadministration.pojo.Teacher">
        insert ignore into teacher
            (teaid, teapwd, teaname, teasex, tearace, teaorigin, teacollege, teapost, teagraduation, teadegree, teaphone, teaphoto)
        VALUES (#{teaid},MD5(#{teapwd}),#{teaname},#{teasex},#{tearace},#{teaorigin},#{teacollege},#{teapost},#{teagraduation},#{teadegree},#{teaphone},#{teaphoto})
    </insert>
    <delete id="deleteTeacher">
        delete from teacher where teaid=#{teaid}
    </delete>
    <update id="inauditTeacher">
        update teacher set teastate=false where teaid=#{teaid}
    </update>
    <update id="auditTeacher">
        update teacher set teastate=true where teaid=#{teaid}
    </update>
    <update id="reset">
        update teacher set teapwd=MD5(#{newpwd}) where teaid=#{teaid} and teapwd=#{teapwd}
    </update>
    <select id="browseTeacher" resultType="com.example.academicadministration.pojo.Teacher">
        select * from teacher where teaid like #{condition} or teaname like #{condition} or teadegree like #{condition} or teagraduation like #{condition}
or teaorigin like #{condition} or tearace like #{condition} or teacollege like #{condition} or teaphone like #{condition} or teapost like #{condition} or teasex like #{condition}
    </select>
</mapper>

VideoMapper.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="com.example.academicadministration.dao.VideoDao">
    <insert id="addVideo" parameterType="com.example.academicadministration.pojo.Video">
        insert into video (courseid, videoname, videointroducation,videocover, videofile,videotime)
        VALUES (#{courseid},#{videoname},#{videointroducation},#{videocover},#{videofile},#{videotime})
    </insert>
    <select id="browseVideo" resultType="com.example.academicadministration.pojo.Video">
        select * from video where videoid like #{condition} or videoname like #{condition} or videointroducation like #{condition} order by videotime
    </select>
    <delete id="deleteVideo">
        delete from video where videoid=#{videoid}
    </delete>
</mapper>

 

标签:mapper,like,courseid,where,select,stuid,condition
From: https://www.cnblogs.com/liyiyang/p/17470990.html

相关文章

  • 导入BaseMapper依赖需要用到的包
    <!--mp依赖mybatisPlus会自动的维护Mybatis以及MyBatis-spring相关的依赖--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus</artifactId><ver......
  • 开发手记:MyBatis的mapper文件的中SQL符号转义
    字符转义问题在MaBatis的XML文件中编写SQL语句时,<符号会出现转义问题,例如:<!--查询指定月份内的订单--><selectid="queryInRange"resultType="OrderEntity"> SELECT*FROMorder WHEREcreate_time>DATE_SUB(NOW(),INTERVAL#{month}MONTH) ANDuser_i......
  • linux系统/dev/mapper/centos-root目录被占满的解决方式
    1、查看虚拟机磁盘使用情况df-h 可以看到/dev/mapper/centos-root已经快满了,这时候就算启动hdfs,也会是强制性的进入安全模式,不让写数据2、查看哪个目录占用过高使用du-h-x--max-depth=1查看哪个目录占用过高,对于过高目录中的内容适当删减腾出一些空间cd/&&du-h......
  • MyBatis源码之getMapper获取代理对象
    MyBatis源码之getMapper获取代理对象下面这句话意思非常明了,就是通过传入接口类型对象,获取接口代理对象。IUserDaouserDao1=sqlSession1.getMapper(IUserDao.class);具体的过程如下:一、首先,调用SqlSession的实现类DefaultSqlSession的getMapper方法,其实是在该方法内调用con......
  • Java学习:使用MyBatis Plus的分页插件和QueryWrapper结合自定义mapper xml实现多表关联
     Vo:/***用来返回给前端展示列表的数据实体*/@DatapublicclassCourseVoimplementsSerializable{privatestaticfinallongserialVersionUID=1L;privateStringid;privateStringtitle;privateStringsubjectParentTitle;private......
  • MapperProxyFactory(映射器代理工厂)的实现原理
    再次回顾Mybatis的基本用法1、定义Mapper接口2、在xml(或注解)中写sqlmybatis帮我们屏蔽了所有和数据库相关的操作,我们只需要给他提供参数、sql、标注返回值的类型即可。通过mapper接口我们可以传递参数、获取返回值;通过xml或者注解我们可以提供需要执行的sql。那么问题来了,究竟......
  • springboot 接入通用tkmapper和pagehelper,boot starter版,mysql5.7,boot2.7.9
    1、pom文件引入<dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.4.6</version></dependency><dependency><groupId......
  • mapperTemp
    @Insert("INSERTINTOcoxisolate.instanceinfo(instance_id,app_name,create_time,update_time,status,readiness_flag,isolate_flag,reason)"+"VALUES(#{instanceId},#{appName},CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,#{status},#{re......
  • 通用 Mapper 的批量插入实现
    具体的SQL模板实现如下所示:importorg.apache.ibatis.mapping.MappedStatement;importtk.mybatis.mapper.MapperException;importtk.mybatis.mapper.entity.EntityColumn;importtk.mybatis.mapper.mapperhelper.EntityHelper;importtk.mybatis.mapper.mapperhelper.Map......
  • springboot+mybatis逆向生成xxxmapper+xxxmapper.xml和xxx实体类
    1.新建springboot工程pom文件如下<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="ht......