myBatis配置

一、主配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

     <!--注册属性文件
    <properties resource="jdbc.properties"/>-->
    <!-- 配置MyBatis运行环境 -->
    <environments default="mysql">
        <environment id="mysql">
            <transactionManager type="JDBC"></transactionManager>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/myschool"/>
                <property name="username" value="root"/>
                <property name="password" value="pwdmysql123"/>
            </dataSource>
        </environment>
    </environments>

    <!-- 注册映射文件 -->
    <mappers>
        <mapper resource="pers/liangcheng/springboot324school/daoimpl/SchoolDaoImpl.xml" />
        <!-- <mapper resource="com/hcx/dao/mapper2.xml"/>  -->
    </mappers>
</configuration>

②properties.yml配置

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/myschool?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
    username: root
    password: pwdmysql123

启动类

@SpringBootApplication
@MapperScan("pers.liangcheng.springboot327school.dao")
public class Springboot327schoolApplication {
    public static void main(String[] args) {
        SpringApplication.run(Springboot327schoolApplication.class, args);
    }
}

二、局部配置文件

<?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">

<!-- namespace:命名空间,用于隔离sql-->
<mapper namespace="pers.liangcheng.springboot327school.dao.TeachAreaDao">

    <select id="allTeach" parameterType="pers.liangcheng.springboot327school.entity.TeachArea" resultType="pers.liangcheng.springboot327school.entity.TeachArea">
        SELECT * FROM teach_area where 1=1
        <if test="teach_area_name != null and teach_area_name != ''">
            and teach_area_name like concat('%',#{teach_area_name},'%')
        </if>
        and isdelete="0"
    </select>

    <select id="findByTeachId" resultType="pers.liangcheng.springboot327school.entity.TeachArea" parameterType="java.lang.Integer">
        SELECT * FROM teach_area WHERE id=#{id}
    </select>

    <update id="updateTeach" parameterType="pers.liangcheng.springboot327school.entity.TeachArea">
        Update teach_area SET  teach_area_name=#{teach_area_name} where id=#{id}
    </update>

    <insert id="addTeach" parameterType="pers.liangcheng.springboot327school.entity.TeachArea">
        INSERT INTO teach_area values (null,#{teach_area_name},#{isdelete})
    </insert>
    <!--物理删除-->
    <delete id="deleteTeach" parameterType="java.lang.Integer">
        DELETE FROM teach_area WHERE id=#{id}
    </delete>
    <!--逻辑删除-->
    <update id="isdeleteTeach" parameterType="pers.liangcheng.springboot327school.entity.TeachArea">
        Update teach_area SET  isdelete="1" where id=#{id}
    </update>
</mapper>

Dao层

public interface TeachAreaDao {

    List<TeachArea> allTeach(String teach_area_name);

    TeachArea findByTeachId(Integer id);

    int updateTeach(TeachArea teachArea);
	//逻辑删除
    int isdeleteTeach(TeachArea teachArea);
	
    int addTeach(TeachArea teachArea);
	//物理删除
    int deleteTeach(Integer id);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值