spring mybatis学习,简单的项目创建

这是一个spring集成mybatis的小项目实践,通过spring的bean管理,配置mybatis的mapper,同时使用阿里巴巴连接池druid,连接到postgresql数据库,实现insert插入操作

  1. 首先使用eclipse创建一个maven项目(single maven project),编辑pom

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    <build>
    <finalName>test</finalName>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    </configuration>
    </plugin>
    </plugins>
    </build>
    <dependencies>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.3.3.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>4.3.3.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.0-b01</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.1.2.Final</version>
    </dependency>
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.26</version>
    </dependency>
    <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.3-1104-jdbc41</version>
    </dependency>
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.1</version>
    </dependency>
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.0</version>
    </dependency>
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.20</version>
    </dependency>
    </dependencies>
  2. 服务器启动首先加载web.xml配置文件,在这里我们设置一个welcome file,指向index.jsp,index.jsp里面其实只是一个form表单,表单提交是有一个servlet控制,后台servlet使用dopost方法获取前台表单填充参数,并存储到数据库,下面是web配置文件。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <!-- 使用contextConfigLocation获取并初始化spring配置文件 -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- 服务器启动,初始化servlet,可以通过他获取spring上下文的bean,里面有个init()方法 -->
    <servlet>
    <servlet-name>ServerApplicationContext</servlet-name>
    <servlet-class>com.spring.mybatis.servlet.ServerApplicationContext</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- 这个是获取页面输入数据的servlet,并调用service层接口存储数据 -->
    <servlet>
    <servlet-name>ServletLogin</servlet-name>
    <servlet-class>com.spring.mybatis.servlet.LoginServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <!-- 这里是阿里连接池druid的监控配置 -->
    <filter>
    <filter-name>DruidWebStatFilter</filter-name>
    <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
    <init-param>
    <param-name>exclusions</param-name>
    <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*,/rs/*</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>DruidWebStatFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
    <servlet-name>DruidStatView</servlet-name>
    <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>DruidStatView</servlet-name>
    <url-pattern>/druid/*</url-pattern>
    </servlet-mapping>
    <!-- web初始化默认加载的页面 -->
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
  3. 我们下面来看一下spring配置文件里面bean的配置,当我们配置bean的时候,应该注意他们的业务范围,以及应该怎样注入,这里使用的setter注入方式,从web.xml中可以看出spring配置文件是在WEB-INF下面的applicationContext.xml,文件内容是:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">
    <bean id="loginService" class="com.spring.mybatis.service.impl.LoginServiceImpl">
    <property name="loginDao" ref="loginDao"></property>
    </bean>
    <bean id="loginDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
    <property name="mapperInterface" value="com.spring.mybatis.dao.LoginDao"></property>
    <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
    </bean>
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" value="classpath*:com/spring/mybatis/mapper/*Mapper.xml"></property>
    </bean>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method = "close">
    <property name="driverClassName" value="org.postgresql.Driver"></property>
    <property name="url" value="jdbc:postgresql://localhost:5432/test_mybatis_db"></property>
    <property name="username" value="postgres"></property>
    <property name="password" value="dbms4Fna"></property>
    <property name="maxActive" value="20"></property>
    <property name="maxIdle" value="20"></property>
    <property name="maxWait" value="6000"></property>
    <property name="defaultAutoCommit" value="true"></property>
    </bean>
    </beans>

注入顺序大概是:
dataSource —>sqlSessionFactory —>loginDao —>loginService

  1. 我们的页面代码很简单,一个form表单

    1
    2
    3
    4
    5
    6
    7
    <form action="LoginServlet" method="post">
    用户名:<br>
    <input type="text" name="username"><br>
    密 码:<br>
    <input type="text" name="password"><br>
    <input type="submit" value="提交">
    </form>
  2. 下面是我们配置的一个servlet类,其中一个是为了在初始化时获得ApplicationContext,即ServerApplicationContext.java

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    package com.spring.mybatis.servlet;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import org.springframework.context.ApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;
    public class ServerApplicationContext extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static ApplicationContext serverContext = null;
    @Override
    public void init() throws ServletException {
    super.init();
    javax.servlet.ServletContext servletContext = getServletContext();
    serverContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    System.out.println("================");
    System.out.println("==serverContext begin==");
    System.out.println("================");
    }
    public static ApplicationContext getApplicationContext() {
    return serverContext;
    }
    }
  3. 这也是一个servlet类,类似于处理与前段页面交互的Struts2的Action类

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    package com.spring.mybatis.servlet;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.spring.mybatis.domain.UserInfo;
    import com.spring.mybatis.service.LoginService;
    @WebServlet("/LoginServlet")
    public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public LoginServlet() {
    super();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=gb2312");
    request.setCharacterEncoding("gb2312");
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    LoginService loginService = (LoginService) ServerApplicationContext.getApplicationContext().getBean("loginService");
    int age = 14;
    char sex = '男';
    int weight = 42;
    UserInfo ui = new UserInfo();
    ui.setUsername(username);
    ui.setPassword(password);
    ui.setAge(age);
    ui.setSex(sex);
    ui.setWeight(weight);
    loginService.insertUserInfo(ui);
    /*try {
    Class.forName("org.postgresql.Driver");
    } catch (Exception e) {
    System.out.print("Class Not Found Exception");
    }
    String url = "jdbc:postgresql://localhost:5432/test_mybatis_db";
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
    conn = (Connection) DriverManager.getConnection(url,"postgres","dbms4Fna");
    stmt = (Statement) conn.createStatement();
    String sql = "insert into userinfo (username,userpsw,age,sex,weight) values ('"+username+"','"+psw+"',25,'男',52)";
    PreparedStatement ps = conn.prepareStatement(sql);
    int result=ps.executeUpdate();
    if( result>0 ){
    System.out.println("Insert OK");
    }
    } catch (Exception e) {
    e.printStackTrace();
    }*/
    }
    }
  4. 上面的LoginServlet里调用了service层接口

    1
    2
    3
    4
    5
    6
    7
    8
    package com.spring.mybatis.service;
    import com.spring.mybatis.domain.UserInfo;
    public interface LoginService {
    public void insertUserInfo(UserInfo userInfo);
    }
  5. 接下来是service层接口的实现类,调用dao

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    package com.spring.mybatis.service.impl;
    import com.spring.mybatis.dao.LoginDao;
    import com.spring.mybatis.domain.UserInfo;
    import com.spring.mybatis.service.LoginService;
    public class LoginServiceImpl implements LoginService {
    private LoginDao loginDao ;
    public void setLoginDao(LoginDao loginDao) {
    this.loginDao = loginDao;
    }
    @Override
    public void insertUserInfo(UserInfo userInfo) {
    loginDao.insertUserInfo(userInfo);
    }
    }
  6. 在我们的dao层只需要定义一个接口即可

    1
    2
    3
    4
    5
    6
    7
    8
    package com.spring.mybatis.dao;
    import com.spring.mybatis.domain.UserInfo;
    public interface LoginDao {
    public void insertUserInfo(UserInfo userInfo);
    }
  7. 下面是mybatis重要的类,首先我们定义pojo(domain),可以根据此pojo自动生成sql代码,连接并操作数据库

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    package com.spring.mybatis.domain;
    public class UserInfo {
    private String username;
    private String password;
    private int age;
    private char sex;
    private int weight;
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }
    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    public int getWeight() {
    return weight;
    }
    public void setWeight(int weight) {
    this.weight = weight;
    }
    public char getSex() {
    return sex;
    }
    public void setSex(char sex) {
    this.sex = sex;
    }
    @Override
    public String toString() {
    return "UserInfo [username=" + username + ", password=" + password + ", age=" + age + ", sex=" + sex
    + ", weight=" + weight + "]";
    }
    }
  8. 创建mapper包,存放mapper.xml文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <!-- 注意这里的命名空间要指向dao,类型指向domain对应实体类 -->
    <mapper namespace="com.spring.mybatis.dao.LoginDao" >
    <resultMap id="BaseResultMap" type="com.spring.mybatis.domain.UserInfo" >
    <id column="username" property="username" jdbcType="VARCHAR" />
    <result column="userpsw" property="password" jdbcType="VARCHAR" />
    <result column="age" property="age" jdbcType="INTEGER" />
    <result column="sex" property="sex" jdbcType="CHAR" />
    <result column="weight" property="weight" jdbcType="INTEGER" />
    </resultMap>
    <!-- 这里的id要和dao接口的方法名对应 -->
    <insert id="insertUserInfo" parameterType="com.spring.mybatis.domain.UserInfo" >
    insert into public.userinfo (username, userpsw, age,
    sex, weight)
    values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER},
    #{sex,jdbcType=CHAR}, #{weight,jdbcType=INTEGER})
    </insert>
    </mapper>

Appendix:
附上两个mybatis自动生成的类文件(没有用到)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
package com.spring.mybatis.mapper;
import com.spring.mybatis.domain.UserInfo;
import com.spring.mybatis.entity.UserInfoExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface UserInfoMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int countByExample(UserInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int deleteByExample(UserInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int deleteByPrimaryKey(String username);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int insert(UserInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int insertSelective(UserInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
List<UserInfo> selectByExample(UserInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
UserInfo selectByPrimaryKey(String username);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int updateByExampleSelective(@Param("record") UserInfo record, @Param("example") UserInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int updateByExample(@Param("record") UserInfo record, @Param("example") UserInfoExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int updateByPrimaryKeySelective(UserInfo record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
int updateByPrimaryKey(UserInfo record);
}
package com.spring.mybatis.entity;
import java.util.ArrayList;
import java.util.List;
public class UserInfoExample {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
protected String orderByClause;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
protected boolean distinct;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
protected List<Criteria> oredCriteria;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public UserInfoExample() {
oredCriteria = new ArrayList<Criteria>();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public boolean isDistinct() {
return distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andUsernameIsNull() {
addCriterion("username is null");
return (Criteria) this;
}
public Criteria andUsernameIsNotNull() {
addCriterion("username is not null");
return (Criteria) this;
}
public Criteria andUsernameEqualTo(String value) {
addCriterion("username =", value, "username");
return (Criteria) this;
}
public Criteria andUsernameNotEqualTo(String value) {
addCriterion("username <>", value, "username");
return (Criteria) this;
}
public Criteria andUsernameGreaterThan(String value) {
addCriterion("username >", value, "username");
return (Criteria) this;
}
public Criteria andUsernameGreaterThanOrEqualTo(String value) {
addCriterion("username >=", value, "username");
return (Criteria) this;
}
public Criteria andUsernameLessThan(String value) {
addCriterion("username <", value, "username");
return (Criteria) this;
}
public Criteria andUsernameLessThanOrEqualTo(String value) {
addCriterion("username <=", value, "username");
return (Criteria) this;
}
public Criteria andUsernameLike(String value) {
addCriterion("username like", value, "username");
return (Criteria) this;
}
public Criteria andUsernameNotLike(String value) {
addCriterion("username not like", value, "username");
return (Criteria) this;
}
public Criteria andUsernameIn(List<String> values) {
addCriterion("username in", values, "username");
return (Criteria) this;
}
public Criteria andUsernameNotIn(List<String> values) {
addCriterion("username not in", values, "username");
return (Criteria) this;
}
public Criteria andUsernameBetween(String value1, String value2) {
addCriterion("username between", value1, value2, "username");
return (Criteria) this;
}
public Criteria andUsernameNotBetween(String value1, String value2) {
addCriterion("username not between", value1, value2, "username");
return (Criteria) this;
}
public Criteria andUserpswIsNull() {
addCriterion("userpsw is null");
return (Criteria) this;
}
public Criteria andUserpswIsNotNull() {
addCriterion("userpsw is not null");
return (Criteria) this;
}
public Criteria andUserpswEqualTo(String value) {
addCriterion("userpsw =", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswNotEqualTo(String value) {
addCriterion("userpsw <>", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswGreaterThan(String value) {
addCriterion("userpsw >", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswGreaterThanOrEqualTo(String value) {
addCriterion("userpsw >=", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswLessThan(String value) {
addCriterion("userpsw <", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswLessThanOrEqualTo(String value) {
addCriterion("userpsw <=", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswLike(String value) {
addCriterion("userpsw like", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswNotLike(String value) {
addCriterion("userpsw not like", value, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswIn(List<String> values) {
addCriterion("userpsw in", values, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswNotIn(List<String> values) {
addCriterion("userpsw not in", values, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswBetween(String value1, String value2) {
addCriterion("userpsw between", value1, value2, "userpsw");
return (Criteria) this;
}
public Criteria andUserpswNotBetween(String value1, String value2) {
addCriterion("userpsw not between", value1, value2, "userpsw");
return (Criteria) this;
}
public Criteria andAgeIsNull() {
addCriterion("age is null");
return (Criteria) this;
}
public Criteria andAgeIsNotNull() {
addCriterion("age is not null");
return (Criteria) this;
}
public Criteria andAgeEqualTo(Integer value) {
addCriterion("age =", value, "age");
return (Criteria) this;
}
public Criteria andAgeNotEqualTo(Integer value) {
addCriterion("age <>", value, "age");
return (Criteria) this;
}
public Criteria andAgeGreaterThan(Integer value) {
addCriterion("age >", value, "age");
return (Criteria) this;
}
public Criteria andAgeGreaterThanOrEqualTo(Integer value) {
addCriterion("age >=", value, "age");
return (Criteria) this;
}
public Criteria andAgeLessThan(Integer value) {
addCriterion("age <", value, "age");
return (Criteria) this;
}
public Criteria andAgeLessThanOrEqualTo(Integer value) {
addCriterion("age <=", value, "age");
return (Criteria) this;
}
public Criteria andAgeIn(List<Integer> values) {
addCriterion("age in", values, "age");
return (Criteria) this;
}
public Criteria andAgeNotIn(List<Integer> values) {
addCriterion("age not in", values, "age");
return (Criteria) this;
}
public Criteria andAgeBetween(Integer value1, Integer value2) {
addCriterion("age between", value1, value2, "age");
return (Criteria) this;
}
public Criteria andAgeNotBetween(Integer value1, Integer value2) {
addCriterion("age not between", value1, value2, "age");
return (Criteria) this;
}
public Criteria andSexIsNull() {
addCriterion("sex is null");
return (Criteria) this;
}
public Criteria andSexIsNotNull() {
addCriterion("sex is not null");
return (Criteria) this;
}
public Criteria andSexEqualTo(String value) {
addCriterion("sex =", value, "sex");
return (Criteria) this;
}
public Criteria andSexNotEqualTo(String value) {
addCriterion("sex <>", value, "sex");
return (Criteria) this;
}
public Criteria andSexGreaterThan(String value) {
addCriterion("sex >", value, "sex");
return (Criteria) this;
}
public Criteria andSexGreaterThanOrEqualTo(String value) {
addCriterion("sex >=", value, "sex");
return (Criteria) this;
}
public Criteria andSexLessThan(String value) {
addCriterion("sex <", value, "sex");
return (Criteria) this;
}
public Criteria andSexLessThanOrEqualTo(String value) {
addCriterion("sex <=", value, "sex");
return (Criteria) this;
}
public Criteria andSexLike(String value) {
addCriterion("sex like", value, "sex");
return (Criteria) this;
}
public Criteria andSexNotLike(String value) {
addCriterion("sex not like", value, "sex");
return (Criteria) this;
}
public Criteria andSexIn(List<String> values) {
addCriterion("sex in", values, "sex");
return (Criteria) this;
}
public Criteria andSexNotIn(List<String> values) {
addCriterion("sex not in", values, "sex");
return (Criteria) this;
}
public Criteria andSexBetween(String value1, String value2) {
addCriterion("sex between", value1, value2, "sex");
return (Criteria) this;
}
public Criteria andSexNotBetween(String value1, String value2) {
addCriterion("sex not between", value1, value2, "sex");
return (Criteria) this;
}
public Criteria andWeightIsNull() {
addCriterion("weight is null");
return (Criteria) this;
}
public Criteria andWeightIsNotNull() {
addCriterion("weight is not null");
return (Criteria) this;
}
public Criteria andWeightEqualTo(Integer value) {
addCriterion("weight =", value, "weight");
return (Criteria) this;
}
public Criteria andWeightNotEqualTo(Integer value) {
addCriterion("weight <>", value, "weight");
return (Criteria) this;
}
public Criteria andWeightGreaterThan(Integer value) {
addCriterion("weight >", value, "weight");
return (Criteria) this;
}
public Criteria andWeightGreaterThanOrEqualTo(Integer value) {
addCriterion("weight >=", value, "weight");
return (Criteria) this;
}
public Criteria andWeightLessThan(Integer value) {
addCriterion("weight <", value, "weight");
return (Criteria) this;
}
public Criteria andWeightLessThanOrEqualTo(Integer value) {
addCriterion("weight <=", value, "weight");
return (Criteria) this;
}
public Criteria andWeightIn(List<Integer> values) {
addCriterion("weight in", values, "weight");
return (Criteria) this;
}
public Criteria andWeightNotIn(List<Integer> values) {
addCriterion("weight not in", values, "weight");
return (Criteria) this;
}
public Criteria andWeightBetween(Integer value1, Integer value2) {
addCriterion("weight between", value1, value2, "weight");
return (Criteria) this;
}
public Criteria andWeightNotBetween(Integer value1, Integer value2) {
addCriterion("weight not between", value1, value2, "weight");
return (Criteria) this;
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table public.userinfo
*
* @mbggenerated do_not_delete_during_merge Fri Mar 10 15:01:14 CST 2017
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table public.userinfo
*
* @mbggenerated Fri Mar 10 15:01:14 CST 2017
*/
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}