README.md 12.0 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
2
# MyBatis JPA Extra
M
readme  
MaxKey 已提交
3
   **MyBatis JPA Extra**对MyBatis扩展JPA功能,旨在基于JPA 2.1的注释简化对单表CUID操作;用Interceptor实现数据库SELECT分页查询;另外提供mybatis-jpa-extra-spring-boot-starter简化SpringBoot集成。
4
 
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
5
相关资源
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
6

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
7
[MyBatis网站][1]
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
8

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
9
[MyBatis GitHub源码][2]
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
10 11


MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
12
## 1、JavaBean注释简单
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
13

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
14
只支持6个注释
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
15
> * @Entity
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
16 17
> * @Table
> * @Column
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
18
> * @Id
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
19
> * @GeneratedValue
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
20 21
> * @Transient 

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
22

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
23
@GeneratedValue有3中策略 
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
24 25

 1. **AUTO**
M
readme  
MaxKey 已提交
26 27 28
	
	snowflakeid
	
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    uuid

    uuid.hex

    serial

 2. **SEQUENCE**
 
    generator值为数据库序列名

 3. **IDENTITY**
 
    generator无,根据数据库自动生成方式

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
43

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
44
```java
M
readme  
MaxKey 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/*
 * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 

package org.apache.mybatis.jpa.test.entity;
MaxKey单点登录官方's avatar
README  
MaxKey单点登录官方 已提交
63

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
64
import java.io.Serializable;
M
readme  
MaxKey 已提交
65

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
66
import javax.persistence.Column;
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
67
import javax.persistence.Entity;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
68 69 70 71
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
M
readme  
MaxKey 已提交
72 73 74 75

import org.apache.mybatis.jpa.persistence.JpaBaseEntity;


MaxKey单点登录官方's avatar
README  
MaxKey单点登录官方 已提交
76 77 78 79 80 81 82 83 84 85 86

/*
   ID                   varchar(40)                    not null,
   NAME                 varchar(60)                    not null,
   STATUS               char(1)                        null,
   CREATEBY             varchar(40)                    null,
   CREATEDATE           date                           null,
   UPDATEBY             varchar(40)                    null,
   UPDATEDATE           date                           null,
   constraint PK_ROLES primary key clustered (ID)
 */
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
87 88
/**
 * @author Crystal.Sea
MaxKey单点登录官方's avatar
README  
MaxKey单点登录官方 已提交
89
 *
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
90
 */
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
91
@Entity
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
92
@Table(name = "STUDENTS")  
M
readme  
MaxKey 已提交
93
public class Students extends JpaBaseEntity implements Serializable{
MaxKey单点登录官方's avatar
README  
MaxKey单点登录官方 已提交
94 95 96 97 98
	/**
	 * 
	 */
	private static final long serialVersionUID = -6928570405840778151L;
	
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
99 100
	@Id
	@Column
M
readme  
MaxKey 已提交
101
	@GeneratedValue(strategy=GenerationType.AUTO,generator="snowflakeid")
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
102
	//@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SEQ_MYBATIS_STUD")
MaxKey单点登录官方's avatar
README  
MaxKey单点登录官方 已提交
103
	//@GeneratedValue(strategy=GenerationType.IDENTITY,generator="SEQ_MYBATIS_STUD")
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117
	private String id;
	@Column
	private String stdNo;
	@Column
	private String stdName;
	@Column
	private String stdGender;
	@Column
	private int stdAge;
	@Column
	private String stdMajor;
	@Column
	private String stdClass;
	
M
readme  
MaxKey 已提交
118 119 120 121
	@Column
	private byte[] images;
	
	
MaxKey单点登录官方's avatar
README  
MaxKey单点登录官方 已提交
122 123 124 125
	public Students() {
		super();
	}

M
readme  
MaxKey 已提交
126

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
127 128 129 130
	public String getStdNo() {
		return stdNo;
	}

M
readme  
MaxKey 已提交
131

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
132 133 134 135
	public void setStdNo(String stdNo) {
		this.stdNo = stdNo;
	}

M
readme  
MaxKey 已提交
136

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
137 138 139 140
	public String getStdName() {
		return stdName;
	}

M
readme  
MaxKey 已提交
141

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
142 143 144 145
	public void setStdName(String stdName) {
		this.stdName = stdName;
	}

M
readme  
MaxKey 已提交
146 147 148 149




MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
150 151 152 153
	public String getStdGender() {
		return stdGender;
	}

M
readme  
MaxKey 已提交
154

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
155 156 157 158
	public void setStdGender(String stdGender) {
		this.stdGender = stdGender;
	}

M
readme  
MaxKey 已提交
159

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
160 161 162 163
	public int getStdAge() {
		return stdAge;
	}

M
readme  
MaxKey 已提交
164

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
165 166 167 168
	public void setStdAge(int stdAge) {
		this.stdAge = stdAge;
	}

M
readme  
MaxKey 已提交
169

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
170 171 172 173
	public String getStdMajor() {
		return stdMajor;
	}

M
readme  
MaxKey 已提交
174

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
175 176 177 178
	public void setStdMajor(String stdMajor) {
		this.stdMajor = stdMajor;
	}

M
readme  
MaxKey 已提交
179

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
180 181 182 183
	public String getStdClass() {
		return stdClass;
	}

M
readme  
MaxKey 已提交
184

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
185 186 187 188
	public void setStdClass(String stdClass) {
		this.stdClass = stdClass;
	}

M
readme  
MaxKey 已提交
189

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
190 191 192 193
	public String getId() {
		return id;
	}

M
readme  
MaxKey 已提交
194

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
195 196 197 198
	public void setId(String id) {
		this.id = id;
	}

M
readme  
MaxKey 已提交
199 200 201 202 203 204 205 206 207 208 209

	public byte[] getImages() {
		return images;
	}


	public void setImages(byte[] images) {
		this.images = images;
	}


MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
210 211
	@Override
	public String toString() {
M
readme  
MaxKey 已提交
212 213
		return "Students [id=" + id + ", stdNo=" + stdNo + ", stdName=" + stdName + ", stdGender=" + stdGender
				+ ", stdAge=" + stdAge + ", stdMajor=" + stdMajor + ", stdClass=" + stdClass + "]";
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
214
	}
M
readme  
MaxKey 已提交
215 216


MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
217 218
}

M
readme  
MaxKey 已提交
219

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
220 221
```

M
readme  
MaxKey 已提交
222
## 2、单表新增、修改、删除、查询、分页查询
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
223 224

```java
M
readme  
MaxKey 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
/*
 * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
242 243 244 245 246 247 248
package org.apache.mybatis.jpa.test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.mybatis.jpa.test.dao.service.StudentsService;
M
readme  
MaxKey 已提交
249
import org.apache.mybatis.jpa.test.entity.Students;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
250 251 252 253 254 255 256 257 258
import org.apache.mybatis.jpa.util.WebContext;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyBatisTestRunner {
M
readme  
MaxKey 已提交
259
	
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
260 261 262
	private static final Logger _logger = LoggerFactory.getLogger(MyBatisTestRunner.class);
	
	public static ApplicationContext context;
MaxKey单点登录官方's avatar
rm  
MaxKey单点登录官方 已提交
263
	public static StudentsService service;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
264
	
M
readme  
MaxKey 已提交
265
	
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
266 267 268 269
	@Test
	public void insert() throws Exception{
		_logger.info("insert...");
		Students student=new Students();
M
readme  
MaxKey 已提交
270
		//student.setId("10024");
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
271 272 273 274 275 276
		student.setStdNo("10024");
		student.setStdGender("M");
		student.setStdName("司马昭");
		student.setStdAge(20);
		student.setStdMajor("政治");
		student.setStdClass("4");
MaxKey单点登录官方's avatar
rm  
MaxKey单点登录官方 已提交
277
		service.insert(student);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
278
		
M
readme  
MaxKey 已提交
279 280 281
		Thread.sleep(1000);
		_logger.info("insert id " + student.getId());
		//service.remove(student.getId());
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
282 283 284 285
		
	}
	
	
M
readme  
MaxKey 已提交
286 287 288
	@Test
	public void merge() throws Exception{
		_logger.info("merge...");
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
289
		Students student=new Students();
M
readme  
MaxKey 已提交
290
		//student.setId("10024");
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
291 292 293 294 295 296
		student.setStdNo("10024");
		student.setStdGender("M");
		student.setStdName("司马昭");
		student.setStdAge(20);
		student.setStdMajor("政治");
		student.setStdClass("4");
M
readme  
MaxKey 已提交
297
		service.merge(student);
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
298 299
		
		Thread.sleep(1000);
M
readme  
MaxKey 已提交
300 301
		_logger.info("insert id " + student.getId());
		//service.remove(student.getId());
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
302 303
		
	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
304
	
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
305 306 307
	@Test
	public void get() throws Exception{
		_logger.info("get...");
M
readme  
MaxKey 已提交
308
		Students student=service.get("317d5eda-927c-4871-a916-472a8062df23");
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
309 310 311
		
		System.out.println("Students "+student);
		 _logger.info("Students "+student);
M
readme  
MaxKey 已提交
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
	}
	
	@Test
	public void update() throws Exception{
		_logger.info("get...");
		Students student=service.get("317d5eda-927c-4871-a916-472a8062df23");
		System.out.println("Students "+student);
		 _logger.info("Students "+student);
		 
		 _logger.info("update...");
		 student.setImages(null);
		 service.update(student);
		 _logger.info("updateed.");
		 
		 student.setImages("ssss".getBytes());
		 service.update(student);
		 _logger.info("updateed2.");
	}
	
	
	@Test
	public void find() throws Exception{
		_logger.info("find...");
		Students student=service.find(Students.class,"317d5eda-927c-4871-a916-472a8062df23");
		
		System.out.println("Students "+student);
		 _logger.info("Students "+student);	 
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
339 340

	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
341
	
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
342 343 344 345 346 347
	@Test
	public void remove() throws Exception{
		
		_logger.info("remove...");
		Students student=new Students();
		student.setId("921d3377-937a-4578-b1e2-92fb23b5e512");
M
readme  
MaxKey 已提交
348
		service.remove(student.getId());
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
349 350 351 352 353 354 355 356 357 358 359
		
	}
	
	@Test
	public void batchDelete() throws Exception{
		_logger.info("batchDelete...");
		List<String> idList=new ArrayList<String>();
		idList.add("8584804d-b5ac-45d2-9f91-4dd8e7a090a7");
		idList.add("ab7422e9-a91a-4840-9e59-9d911257c918");
		idList.add("12b6ceb8-573b-4f01-ad85-cfb24cfa007c");
		idList.add("dafd5ba4-d2e3-4656-bd42-178841e610fe");
M
readme  
MaxKey 已提交
360
		service.batchDelete(idList);
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
361
	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
362 363 364

	@Test
	public void queryPageResults() throws Exception{
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
365
		
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
366 367 368 369 370
		_logger.info("queryPageResults...");
		 Students student=new Students();
		 //student.setId("af04d610-6092-481e-9558-30bd63ef783c");
		 student.setStdGender("M");
		 //student.setStdMajor(政治");
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
371
		 student.setPageSize(10);
M
readme  
MaxKey 已提交
372
		 student.setPageNumber(1);
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
373
		 List<Students> allListStudents = 
M
readme  
MaxKey 已提交
374
				 service.queryPageResults(student).getRows();
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
375 376 377
		 for (Students s : allListStudents) {
			 _logger.info("Students "+s);
		 }
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
378 379 380 381
	}
	
	@Test
	public void queryPageResultsByMapperId() throws Exception{
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
382

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
383 384 385 386
		_logger.info("queryPageResults by mapperId...");
		 Students student=new Students();
		 student.setStdGender("M");
		 //student.setStdMajor(政治");
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
387 388
		 student.setPageSize(10);
		 student.setPageNumber(2);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
389
		 
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
390
		 List<Students> allListStudents = 
M
readme  
MaxKey 已提交
391
				 service.queryPageResults("queryPageResults1",student).getRows();
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
392 393 394
		 for (Students s : allListStudents) {
			 _logger.info("Students "+s);
		 }
M
readme  
MaxKey 已提交
395
		 
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
396
	}
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
397 398
	
	
M
readme  
MaxKey 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
	
	@Test
	public void findAll() throws Exception{
		_logger.info("findAll...");
		List<Students> allListStudents =service.findAll();
		 for (Students s : allListStudents) {
			 _logger.info("Students "+s);
		 }
	}
	
	@Before
	public void initSpringContext(){
		if(context!=null) return;
		_logger.info("init Spring Context...");
		SimpleDateFormat sdf_ymdhms =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String startTime=sdf_ymdhms.format(new Date());
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
415

M
readme  
MaxKey 已提交
416 417 418 419 420 421 422 423 424
		try{
			MyBatisTestRunner runner=new MyBatisTestRunner();
			runner.init();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		_logger.info("-- --Init Start at " + startTime+" , End at  "+sdf_ymdhms.format(new Date()));
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
425
	}
M
readme  
MaxKey 已提交
426 427 428 429 430 431 432 433 434 435 436 437
	
	//Initialization ApplicationContext for Project
	public void init(){
		
		_logger.info("Application dir "+System.getProperty("user.dir"));
		context = new ClassPathXmlApplicationContext(new String[] {"spring/applicationContext.xml"});
		
		WebContext.applicationContext=context;
		service =(StudentsService)WebContext.getBean("studentsService");
		
	}
	
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
438
}
M
readme  
MaxKey 已提交
439

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
440 441
```

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
442 443

## 4、映射文件配置
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
444

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
```xml
<mapper namespace="org.apache.mybatis.jpa.test.dao.persistence.StudentsMapper" >
	<sql id="sql_condition">
		WHERE	1	=	1
    	<if test="id != null">
			AND	ID	=	'${id}'
		</if>
		<if test="stdName != null  and stdName != '' ">
			AND STDNAME like '%${stdName}%'
		</if>
		<if test="stdGender != null  and stdGender != '' ">
			AND	STDGENDER	=	#{stdGender}
		</if>
		<if test="stdMajor != null">
			<![CDATA[AND	STDMAJOR	= #{stdMajor}]]>
		</if>
	</sql>
	
    <select id="queryPageResults" parameterType="Students" resultType="Students">
    	SELECT 
    		ID		   ,
			STDNO      ,
			STDNAME    ,
			STDGENDER  ,
			STDAGE     ,
			STDMAJOR   ,
			STDCLASS 
    	FROM STUDENTS 
    	<include refid="sql_condition"/>
    </select>
 
     <select id="queryPageResults1" parameterType="Students" resultType="Students">
    	SELECT 
    		ID		   ,
			STDNO      ,
			STDNAME    ,
			STDGENDER  ,
			STDAGE     ,
			STDMAJOR   ,
			STDCLASS 
    	FROM STUDENTS 
    	<include refid="sql_condition"/>
    </select>
       
MaxKey单点登录官方's avatar
rm  
MaxKey单点登录官方 已提交
489
     <select id="queryBy" parameterType="Students" resultType="Students">
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
    	SELECT 
    		ID		   ,
			STDNO      ,
			STDNAME    ,
			STDGENDER  ,
			STDAGE     ,
			STDMAJOR   ,
			STDCLASS 
    	FROM ROLES 
    	<include refid="sql_condition"/>
    </select>
  
    <delete id="delete" parameterType="Students" >
    	DELETE FROM STUDENTS WHERE ID=#{id}
    </delete>
    
```


MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
509
##  5、SpringBoot配置
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
510

MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
511 512 513 514 515 516 517 518
```ini
#
spring.datasource.username=root
spring.datasource.password=maxkey
spring.datasource.url=jdbc:mysql://localhost/test?autoReconnect=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

M
readme  
MaxKey 已提交
519 520 521
mybatis.dialect=mysql
mybatis.type-aliases-package=org.apache.mybatis.jpa.test.entity
mybatis.mapper-locations=classpath*:/org/apache/mybatis/jpa/test/dao/persistence/xml/${mybatis.dialect}/*.xml
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
522
mybatis.table-column-escape=true
M
readme  
MaxKey 已提交
523 524
mybatis.table-column-snowflake-datacenter-id=1
mybatis.table-column-snowflake-machine-id=1
MaxKey单点登录官方's avatar
v2.2  
MaxKey单点登录官方 已提交
525
#mybatis.table-column-escape-char=`
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
526
```
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
527

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
528 529 530

  [1]: http://www.mybatis.org/mybatis-3/
  [2]: https://github.com/mybatis/mybatis-3/