mybatis(ibatis)优化
我们在使用mybatis的时候,需要注意mybatis的性能,怎么才能快速提高查询,在编写实体Bean 需要生成getXXX 和setXXX方法 ,在设置settings也需要注意一些选项:
操作方法
- 01
需要在实体Bean里面添加getXXX 和setXXX方法: 比如:UserInfo.java public class UserInfo { private Integer userId; private String userName; private String userSex; private Integer userAge; public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserSex() { return userSex; } public void setUserSex(String userSex) { this.userSex = userSex; } public Integer getUserAge() { return userAge; } public void setUserAge(Integer userAge) { this.userAge = userAge; }
- 02
在设置mybatis-config.xml配置文件里面settings信息: <configuration> <settings> <setting name="cacheModelsEnabled" value="true"/> <setting name="lazyLoadingEnabled" value="true"/> <setting name="enhancementEnabled" value="true"/> <setting name="errorTracingEnabled" value="true"/> <setting name="maxSessions" value="500"/> <setting name="maxTransactions" value="200"/> <setting name="maxRequests" value="1024"/> <setting name="useStatementNamespaces" value="true"/> </settings> <environments default="developments"> <environment id="mysql"> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/test" /> <property name="username" value="root" /> <property name="password" value="root" /> </dataSource> </environment> </environments> <mappers> <mapper resource="com/test/domain/userinfo.xml" /> </mappers> </configuration>