cn域名后缀网站,企业网站建设珠海,抖音代运营销售话术,上海大企业公司排名目录
1. 批量操作:通过标签支持批量插入
2. 批量操作:通过标签支持批量更新
3. 批量操作#xff1a;通过标签支持批量删除
4. 动态SQL
3. 多条件分支查询
4. SQL语句优化#xff1a;使用标签避免多余的AND或OR关键字。
5. 注解方式使用MyBatis
6. 一对多
7. 多对一通过标签支持批量删除
4. 动态SQL
3. 多条件分支查询
4. SQL语句优化使用标签避免多余的AND或OR关键字。
5. 注解方式使用MyBatis
6. 一对多
7. 多对一每个评论Comment都属于一篇文章Article并且每篇文章可以有多个评论。
8. MyBatis-Plus集成 1. 批量操作:通过foreach标签支持批量插入
insert idbatchInsert parameterTypejava.util.ListINSERT INTO user (username, email,phone, create_time) VALUESforeach collectionlist itemitem separator,(#{item.username}, #{item.email},#{item.phone}, #{item.createTime})/foreach
/insert
2. 批量操作:通过foreach标签支持批量更新
update idbatchUpdate parameterTypejava.util.Listforeach collectionlist itemitem separator;UPDATE userSET username #{item.username}, email #{item.email}WHERE id #{item.id}/foreach
/update
3. 批量操作通过foreach标签支持批量删除
delete idbatchDelete parameterTypejava.util.ListDELETE FROM user WHERE id INforeach collectionlist itemid open( separator, close)#{id}/foreach
/delete
4. 动态SQL
select idfindUsers resultTypeUserSELECT * FROM userWHERE 11if testusername ! null and username ! AND username LIKE CONCAT(%, #{username}, %)/ifif testemail ! null and email ! AND email #{email}/ifif teststatus ! nullAND status #{status}/if
/select
3. 多条件分支查询
select idfindUsersByCondition resultTypeUserSELECT * FROM userwherechoosewhen testsearchType usernameusername LIKE CONCAT(%, #{keyword}, %)/whenwhen testsearchType emailemail LIKE CONCAT(%, #{keyword}, %)/whenotherwise(username LIKE CONCAT(%, #{keyword}, %) OR email LIKE CONCAT(%, #{keyword}, %))/otherwise/choose/where
/select
4. SQL语句优化使用trim标签避免多余的AND或OR关键字。
select idfindUsers resultTypeUserSELECT * FROM usertrim prefixWHERE prefixOverridesAND |OR if testusername ! null and username ! AND username LIKE CONCAT(%, #{username}, %)/ifif testemail ! null and email ! AND email #{email}/ifif teststatus ! nullAND status #{status}/if/trim
/select
5. 注解方式使用MyBatis
public interface UserMapper {Select(SELECT * FROM user WHERE id #{id})User getUserById(Long id);Insert(INSERT INTO user (username, email, create_time) VALUES (#{username}, #{email}, #{createTime}))Options(useGeneratedKeys true, keyProperty id)int insertUser(User user);Update(UPDATE user SET username #{username}, email #{email} WHERE id #{id})int updateUser(User user);Delete(DELETE FROM user WHERE id #{id})int deleteUser(Long id);
}
6. 一对多
resultMap iduserWithOrdersMap typeUserid propertyid columnuser_id/result propertyusername columnusername/collection propertyorders ofTypeOrderid propertyid columnorder_id/result propertyorderNumber columnorder_number/result propertycreateTime columnorder_create_time//collection
/resultMapselect idgetUserWithOrders resultMapuserWithOrdersMapSELECT u.id as user_id, u.username, o.id as order_id, o.order_number, o.create_time as order_create_timeFROM user uLEFT JOIN orders o ON u.id o.user_idWHERE u.id #{userId}
/select
7. 多对一每个评论Comment都属于一篇文章Article并且每篇文章可以有多个评论。
?xml version1.0 encodingUTF-8 ?
!DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtdmapper namespacecom.example.mapper.ArticleMapper!-- 定义 Comment 的 resultMap --resultMap idcommentWithArticleMap typeCommentid propertyid columncomment_id/result propertycontent columncomment_content/result propertycreateTime columncomment_create_time/association propertyarticle javaTypeArticleid propertyid columnarticle_id/result propertytitle columnarticle_title/result propertycontent columnarticle_content//association/resultMap!-- 定义 Article 的 resultMap --resultMap idarticleWithCommentsMap typeArticleid propertyid columnarticle_id/result propertytitle columnarticle_title/result propertycontent columnarticle_content/collection propertycomments ofTypeComment resultMapcommentWithArticleMap//resultMap!-- 查询文章及其评论列表 --select idgetArticleWithComments resultMaparticleWithCommentsMapSELECT a.id as article_id,a.title as article_title,a.content as article_content,c.id as comment_id,c.content as comment_content,c.create_time as comment_create_timeFROM article aLEFT JOIN comment c ON a.id c.article_idWHERE a.id #{articleId}/select/mapper
8. MyBatis-Plus集成
Service
public class UserServiceImpl extends ServiceImplUserMapper, User implements UserService {public ListUser findUsersByCondition(String username, String email) {return this.list(new QueryWrapperUser().like(StringUtils.isNotBlank(username), username, username).eq(StringUtils.isNotBlank(email), email, email));}
}