<> Learning objectives :

mybatis-plus Multi table Association query

<> Learning content :

mybatis-plus Multi table Association query

* Part code of entity class @Data @AllArgsConstructor @NoArgsConstructor @TableName("wb_member")
public class WbMember implements Serializable { private static final long
serialVersionUID=1L; /** * user ID */ @ApiModelProperty(value = " user ID", position =
0) @TableId(value = "id", type = IdType.ASSIGN_ID) @JsonFormat(shape =
JsonFormat.Shape.STRING) private Long id; /** * nickname */ @ApiModelProperty(value =
" nickname ", position = 1) private String nickName; /** * phone number */ @ApiModelProperty(
value= " phone number ", position = 2) private String phone; /** * password */ @ApiModelProperty
(value = " password ", position = 3) private String password;
* Test interface /** * Test interface * @return */ @ApiOperation(" test ") @PostMapping(
"/list/testMember") public AjaxResult testMember(){ long id = 1339284736172032l;
return AjaxResult.success(iWbMemberService.queryTest(id)); }
* mapper inherit BaseMapper Interface public interface WbMemberMapper extends BaseMapper<
WbMember> { @Select({ "select", "* ", "from wb_member", "where id =
#{id,jdbcType=INTEGER}" }) @Results({ @Result(column="id", property="id",
jdbcType=JdbcType.INTEGER, id=true), @Result(column="nick_name", property=
"nickName", jdbcType=JdbcType.VARCHAR), @Result(column="phone", property="phone"
, jdbcType=JdbcType.VARCHAR), @Result(column="sex", property="sex", jdbcType=
JdbcType.INTEGER), @Result(column="birthday", property="birthday", jdbcType=
JdbcType.VARCHAR) }) List<WbMember> queryTest(long id); }
* No need to write xml file ,sql Written in mapper Interface annotation , have access to mybatis-plus generator
* database

The query result is :

* Key parts
Single table query results are normal , Parameter transmission is normal , We can try to query by passing parameters through multi table Association .

* Modify to multi table query
* An object should be encapsulated here, which may be easier to maintain , The test is written map @Select({ "select",
"u.user_id,u.user_name,u.nick_name ", "from sys_user u,sys_user_role r,sys_role
o", "where u.user_id = r.user_id AND r.role_id = o.role_id", "AND u.user_id =
#{id,jdbcType=INTEGER}" }) @Results({ @Result(column="user_id", property=
"userId", jdbcType=JdbcType.INTEGER, id=true), @Result(column="user_name",
property="userName", jdbcType=JdbcType.VARCHAR), @Result(column="nick_name",
property="nickName", jdbcType=JdbcType.VARCHAR), }) List<Map> queryTest(long id)
;

Test results and mybatis Written xml Consistent operation results , So this method can also be realized mybatis-plus Multi table Association query

<> Learning output :

adopt mapper Chinese writing sql Get multi table Association query .

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?