zoukankan      html  css  js  c++  java
  • myBatis 双配置文件实现增删改查

    sqlMappConfig.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="cn.kgc.Dao.Users">
    <!--查询所有-->
    <select id="findAll" resultType="cn.kgc.Users">
    select * from users;
    </select>

    <!--添加-->
    <insert id="addUsers" parameterType="cn.kgc.Users">
    insert into users values (null,#{userName},#{password},#{sex},#{address});
    </insert>

    <!--修改-->
    <update id="update" parameterType="cn.kgc.Users">
    update users set userName = #{userName},password =#{password},sex=#{sex},address=#{address} where id=#{id};
    </update>

    <!--删除-->
    <delete id="delete" parameterType="java.lang.Integer">
    delete from users where id = #{value};
    </delete>

    <!--模糊查询-->
    <select id="selectByUserName" resultType="cn.kgc.Users" parameterType="java.lang.String">
    select * from users where userName like "%"#{userName}"%"
    </select>

    <!--根据ID查询-->
    <select id="selectById" resultType="cn.kgc.Users" parameterType="java.lang.Integer">
    select * from users where id=#{id};
    </select>
    </mapper>
    userMapper.xml-----配置数据库连接和映射文件路径
    <?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>
    <environments default="development">
    <environment id="development">
    <transactionManager type="JDBC" />
    <dataSource type="POOLED">
    <property name="driver" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://127.0.0.1:3306/mybatis?characterEncoding=utf8" />
    <property name="username" value="root" />
    <property name="password" value="123456" />
    </dataSource>
    </environment>
    </environments>
    <!--映射文件路径-->
    <mappers>
    <mapper resource="cn/kgc/UserMapper.xml"></mapper>
    </mappers>
    </configuration>


  • 相关阅读:
    jq使用手册
    MVC4 Forms 验证,部署到Hyper-v上.FormsAuthentication.SetAuthCookie无效的问题
    ASP.NET FormsAuthentication跨站点登录时绝对地址返回的问题
    FireBird.conf 常用参数说明 (FrieBird3.0.4版)
    AnkhSVN2019
    控制台程序的RedirectStandardOutput
    代替webbrowser的插件:CefSharp
    mssql分区视图
    Firebird写存储过程
    .net项目多个目标架构
  • 原文地址:https://www.cnblogs.com/geng-geng1997/p/11358834.html
Copyright © 2011-2022 走看看