1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper 3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5 <mapper namespace="Customer"> 6 7 8 <select id="findCustomerById" parameterType="int" resultType="org.mybatis.model.Customer"> 9 select * from customer where id=#{id}<!-- #{}表示占位符 --> 10 </select> 11 12 <select id="findCustomerById2" parameterType="int" resultType="Customer"> 13 select * from customer where id=#{id} 14 </select> 15 16 <select id="findCustomerByName" parameterType="String" resultType="Customer"> 17 select * from customer where name like ‘%${value}%‘<!-- ${}是一种拼接符,表示不加单引号等任何修饰,不能防止sql注入 --> 18 </select> 19 20 <select id="findCustomerByName2" parameterType="String" resultType="Customer"><!-- 对上一种方式的改进 --> 21 select * from customer where name like ‘%‘||#{value}||‘%‘ 22 </select> 23 24 <insert id="insertCustomer" parameterType="Customer"> 25 <selectKey keyProperty="id" order="BEFORE" resultType="int"><!-- 插入前,查询最大ID,并赋值给当前对象 --> 26 select nvl(max(id),0)+1 from customer 27 </selectKey> 28 insert into customer(id,name,birthday,sex,address) values (#{id},#{name},#{birthday},#{sex},#{address}) 29 </insert> 30 31 <insert id="insertCustomer2" parameterType="Customer"> 32 insert into customer(id,name,birthday,sex,address) values (#{id},#{name},#{birthday},#{sex},#{address}) 33 <selectKey keyProperty="id" order="AFTER" resultType="int"><!-- 插入后,查询最大ID,并赋值给当前对象 --> 34 select max(id) from customer 35 </selectKey> 36 </insert> 37 38 <delete id="deleteCustomer" parameterType="int"> 39 delete from customer where id=#{id} 40 </delete> 41 42 <update id="updateCustomer" parameterType="Customer"> 43 update customer set name=#{name},sex=#{sex},birthday=#{birthday},address=#{address} where id=#{id} 44 </update> 45 46 </mapper>
阿萨德发士大夫11111111 2 3 2 3 2 3
111111111111111111111111111
<?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="Customer"> <select id="findCustomerById" parameterType="int" resultType="org.mybatis.model.Customer"> select * from customer where id=#{id}<!-- #{}表示占位符 --> </select> <select id="findCustomerById2" parameterType="int" resultType="Customer"> select * from customer where id=#{id} </select> <select id="findCustomerByName" parameterType="String" resultType="Customer"> select * from customer where name like ‘%${value}%‘<!-- ${}是一种拼接符,表示不加单引号等任何修饰,不能防止sql注入 --> </select> <select id="findCustomerByName2" parameterType="String" resultType="Customer"><!-- 对上一种方式的改进 --> select * from customer where name like ‘%‘||#{value}||‘%‘ </select> <insert id="insertCustomer" parameterType="Customer"> <selectKey keyProperty="id" order="BEFORE" resultType="int"><!-- 插入前,查询最大ID,并赋值给当前对象 --> select nvl(max(id),0)+1 from customer </selectKey> insert into customer(id,name,birthday,sex,address) values (#{id},#{name},#{birthday},#{sex},#{address}) </insert> <insert id="insertCustomer2" parameterType="Customer"> insert into customer(id,name,birthday,sex,address) values (#{id},#{name},#{birthday},#{sex},#{address}) <selectKey keyProperty="id" order="AFTER" resultType="int"><!-- 插入后,查询最大ID,并赋值给当前对象 --> select max(id) from customer </selectKey> </insert> <delete id="deleteCustomer" parameterType="int"> delete from customer where id=#{id} </delete> <update id="updateCustomer" parameterType="Customer"> update customer set name=#{name},sex=#{sex},birthday=#{birthday},address=#{address} where id=#{id} </update> </mapper>
时间: 2024-10-08 03:16:13