<?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.njupt.pojo.User">
<select id="selectUserById" parameterType="string" resultType="com.njupt.pojo.User">
select id ,name username , address from user where id = #{id}
</select>
<select id="selectAllUsers" resultType="com.njupt.pojo.User">
select id ,name , address from user
</select>
<insert id="insertUser" parameterType="com.njupt.pojo.User">
insert into user(id ,name , address) values(#{id},#{username},#{address})
</insert>
<select id="selectUserByIdForMap" parameterType="string" resultType="hashmap">
select id ,name ,address from user where id = #{id}
</select>
<insert id="insertUserForMap" parameterType="hashmap">
insert into user(id,name,address) values(#{id},#{username1},#{address});
</insert>
<delete id="deleteUserById" parameterType="string">
delete from user where id = #{id}
</delete>
<update id="updateUserById" parameterType="com.njupt.pojo.User">
update user set name = #{username} ,address = #{address} where id = #{id}
</update>
<update id="updateUserByIdForMap" parameterType="hashmap">
update user set name = #{username2},address=#{address} where id = #{id}
</update>
<select id="selectUserByCondition" parameterType="com.njupt.pojo.User" resultType="com.njupt.pojo.User">
select id , name username ,address from user where 1 = 1
<if test="id != null">
and id = #{id}
</if>
<if test="username != null">
and name = #{username}
</if>
<if test="address != null">
and address = #{address}
</if>
</select>
<select id="selectUserByCondition1" parameterType="com.njupt.pojo.User" resultType="com.njupt.pojo.User">
select id ,name as username ,address from user
<where>
<if test="id != null">
id = #{id}
</if>
<if test="username != null">
and name = #{username}
</if>
<if test="address != null">
and address = #{address}
</if>
</where>
</select>
</mapper>
MyBatis之User.xml
原创CAIHONGSHIJIE6 博主文章分类:mybatis ©著作权
©著作权归作者所有:来自51CTO博客作者CAIHONGSHIJIE6的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:spring中事务管理
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MyBatis之sqlMapConfig.xml
PUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
MyBatis sqlMapConfig.xml xml mysql bc -
Mybatis之XML映射文件
MyBatis 针对 SQL 构建,真正强大在于它的映射语句。 SQL 映射文件有很少的几个顶级元素(按照它们应该被定义的顺序): cache – 给定命名空间的缓存配置。 cache-ref– 其他命名空间缓存配置的引用。
Mybatis XML映射 增、删、改、查 cache 主键自增 -
前后端分离模式 springboot
简述对前后端分离的工作模式的认识 一、前后端分离的基本概念 前端后端交互,基本上是基于http+json的形式。后端人员专注于提供数据,更重要职责是维护系统架构的稳定,保证数据的安全。前端人员专注于交互,快速响应UI的变化。 双方交互基于ht
前后端分离模式 springboot 前后端分离 json 提供数据