mybatis xml查询语句大全
Posted xiaolei2017
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis xml查询语句大全相关的知识,希望对你有一定的参考价值。
package com.csf.rml.dao; import java.util.List; import com.csf.rml.entity.Muser; import org.apache.ibatis.annotations.Param; public interface MuserMapper { int deleteByPrimaryKey(@Param("id") Integer id); int insert(Muser record); int insertSelective(Muser record); Muser selectByPrimaryKey(@Param("id") Integer id); int updateByPrimaryKeySelective(Muser record); int updateByPrimaryKey(Muser record); List<Muser> getAll(); List<Muser> searchAll(@Param("name") String name); } --------------------------------------------------------------------------------------------------------------- <?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.csf.rml.dao.MuserMapper"> <resultMap id="BaseResultMap" type="com.csf.rml.entity.Muser"> <id column="id" property="id"/> <result column="name" property="name"/> <result column="age" property="age"/> <result column="address" property="address"/> </resultMap> <sql id="Base_Column_List"> id, name, age, address </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer"> select <include refid="Base_Column_List"/> from muser where ID = #{id} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> delete from muser where id = #{id} </delete> <insert id="insert" parameterType="com.csf.rml.entity.Muser"> insert into muser (name, age, address) values (#{name}, #{age},#{address}) </insert> <insert id="insertSelective" parameterType="com.csf.rml.entity.Muser"> insert into muser <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null and id != 0">id,</if> <if test="name != null and name != ‘‘">name,</if> <if test="age != null and age != ‘‘">age,</if> <if test="address != null and address != ‘‘">address,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null and id != 0">#{id},</if> <if test="name != null and name != ‘‘">#{name},</if> <if test="age != null and age != ‘‘">#{age},</if> <if test="address != null and address != ‘‘">#{address},</if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.csf.rml.entity.Muser"> update MUSER <set> <if test="name != null and name != ‘‘"> NAME = #{name}, </if> <if test="age != null and age != ‘‘"> AGE = #{age}, </if> <if test="address != null and address != ‘‘"> ADDRESS = #{address}, </if> </set> where ID = #{id} </update> <update id="updateByPrimaryKey" parameterType="com.csf.rml.entity.Muser"> update muser set name = #{name}, age = #{age}, address = #{address} where id = #{id} </update> <select id="getAll" resultMap="BaseResultMap"> select ID, NAME, AGE, ADDRESS from muser </select> <select id="searchAll" resultType="com.csf.rml.entity.Muser" parameterType="java.lang.String"> select * from muser <where> <if test="name != null and name != ‘‘"> name like concat("%",#{name},"%") </if> </where> ORDER BY id asc </select> </mapper> ============================================================================================================== package com.csf.szclient.mysql.dao; import com.csf.szclient.mysql.entity.HqStockTrade; import org.apache.ibatis.annotations.Param; import java.util.List; /** * Created by james.qian on 2016/9/22. */ public interface HqStockTradeDao { void insertHqStockTradeList(List<HqStockTrade> list); List<HqStockTrade> getZqjbList(@Param("dt") String date); List<HqStockTrade> findByDate(@Param("dt") String date); List<HqStockTrade> findByDate21(@Param("dt") String date); void updateTpbz(@Param("ticks") List<String> ticks, @Param("value") String value); void updateLstp(@Param("ticks") List<String> ticks, @Param("value") String value); } --------------------------------------------------------------------------------------------------------------- <?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.csf.szclient.mysql.dao.HqStockTradeDao"> <!--批量录入数据--> <insert id="insertHqStockTradeList" parameterType="com.csf.szclient.mysql.entity.HqStockTrade"> INSERT INTO hq_stock_trade (dt,tick,jyzt,zqjb,tpbz,cqcx,lstp) VALUES <foreach collection="list" item="i" separator=","> (#{i.dt},#{i.tick},#{i.jyzt},#{i.zqjb},#{i.tpbz},#{i.cqcx},#{i.lstp}) </foreach> ON duplicate KEY UPDATE jyzt=VALUES(jyzt), zqjb=VALUES(zqjb), tpbz=VALUES(tpbz), cqcx=VALUES(cqcx), lstp=VALUES(lstp) </insert> <!--获取所有股票上一个交易日的交易状态--> <select id="getZqjbList" resultType="com.csf.szclient.mysql.entity.HqStockTrade"> <![CDATA[ SELECT dt, tick, zqjb FROM hq_stock_trade WHERE dt = #{dt} AND (zqjb = ‘S‘ OR zqjb = ‘*‘) ]]> </select> <!-- 获取所有股票某一天的数据 --> <select id="findByDate" parameterType="String" resultType="com.csf.szclient.mysql.entity.HqStockTrade"> <![CDATA[ SELECT id, dt, tick, jyzt, zqjb, tpbz, cqcx, lstp, upt FROM hq_stock_trade WHERE dt = #{dt} ]]> </select> <select id="findByDate21" parameterType="String" resultType="com.csf.szclient.mysql.entity.HqStockTrade"> <![CDATA[ SELECT id, dt, tick, jyzt, zqjb, tpbz, cqcx, lstp, upt FROM hq_stock_trade_21 WHERE dt = #{dt} ]]> </select> <!-- 更新tpbz字段 --> <insert id="updateTpbz"> INSERT INTO hq_stock_trade (dt, tick, jyzt, zqjb, tpbz, cqcx, lstp) VALUES <foreach collection="ticks" item="tick" separator=","> (now(), #{tick}, ‘N‘, ‘N‘, #{value}, ‘N‘, ‘N‘) </foreach> on duplicate key update tpbz=#{value} </insert> <!-- 更新lstp字段 --> <insert id="updateLstp"> INSERT INTO hq_stock_trade (dt, tick, jyzt, zqjb, tpbz, cqcx, lstp) VALUES <foreach collection="ticks" item="tick" separator=","> (now(), #{tick}, ‘N‘, ‘N‘, ‘F‘, ‘N‘, #{value}) </foreach> on duplicate key update lstp=#{value} </insert> </mapper> ============================================================================================================== package com.csf.kam.weui.dao; import java.util.List; import org.apache.ibatis.annotations.Param; import com.csf.kam.weui.entity.TopicHot; /** * 概念热度追踪表 * * @author fenglei.ma 2017/07/13 9:55 */ public interface TopicHotDao { // 查询所有 List<TopicHot> findAll(@Param("offset") Integer offset, @Param("limit") Integer limit); // 总条数 int findTotal(); } --------------------------------------------------------------------------------------------------------------- <?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.csf.kam.weui.dao.TopicHotDao"> <!-- 查询所有 --> <select id="findAll" resultType="com.csf.kam.weui.entity.TopicHot" parameterType="Integer"> <![CDATA[ SELECT * FROM topic_hot ORDER BY update_time desc LIMIT #{offset},#{limit} ]]> </select> <!-- 查询总条数 --> <select id="findTotal" resultType="Integer"> <![CDATA[ select count(1) from topic_hot ]]> </select> </mapper> ============================================================================================================== package com.ruoyi.project.system.user.mapper; import java.util.List; import com.ruoyi.project.system.user.domain.UserRole; /** * 用户表 数据层 * * @author ruoyi */ public interface UserRoleMapper { public int deleteUserRoleByUserId(Long userId); public int deleteUserRole(Long[] ids); public int selectCountUserRoleByRoleId(Long roleId); public int batchUserRole(List<UserRole> userRoleList); } --------------------------------------------------------------------------------------------------------------- <?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.ruoyi.project.system.user.mapper.UserRoleMapper"> <resultMap type="UserRole" id="UserRoleResult"> <result property="userId" column="user_id" /> <result property="roleId" column="role_id" /> </resultMap> <delete id="deleteUserRoleByUserId" parameterType="Long"> delete from sys_user_role where user_id=#{userId} </delete> <select id="selectCountUserRoleByRoleId" resultType="Integer"> select count(*) from sys_user_role where role_id=#{roleId} </select> <delete id="deleteUserRole" parameterType="Long"> delete from sys_user_role where user_id in <foreach collection="array" item="userId" open="(" separator="," close=")"> #{userId} </foreach> </delete> <insert id="batchUserRole"> insert into sys_user_role(user_id, role_id) values <foreach item="item" index="index" collection="list" separator=","> (#{item.userId},#{item.roleId}) </foreach> </insert> </mapper>
以上是关于mybatis xml查询语句大全的主要内容,如果未能解决你的问题,请参考以下文章