The following is an editing of idea2018
New Maven Project
1 file ->new ->project
Programmer load the plug at the bottom right after New. This time need a moment, after loading good software package directories will be one more ja
It looks like this:
To test the database, we need to build a table,
Then the new query:
CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(32) NOT NULL COMMENT '用户名称',
`birthday` datetime default NULL COMMENT '生日',
`sex` char(1) default NULL COMMENT '性别',
`address` varchar(256) default NULL COMMENT '地址',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Adding a new data table ,, command:
nsert into `user` (` id`, `username`,` birthday`, `sex`,` address`) values (41, 'Wang', '2018-02-27 17:47:08', 'M ',' Beijing '), (42,' small two kings ',' 2018-03-02 15:09:37 ',' female ',' Beijing Jinyan Long '), (43,' small two kings ',' 2018 -03-04 11:34:34 ',' female ',' Beijing Jinyan Long '), (45,' Chi Chuan podcast ',' 2018-03-04 12:04:06 ',' male ',' Beijing Jinyan Long '), (46,' Pharaoh ',' 2018-03-07 17:37:26 ',' male ',' Beijing '), (48,' small Ma Baoli ',' 2018-03-08 11:44 : 00 ',' female ',' Beijing amendment ');
Then through the main load the required plug-Package Configuration:
Add in pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.itheima</groupId> <artifactId>day01_eesy_01mybatis</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.5</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.12</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> </dependency> </dependencies> </project>
Which is explained as follows:
So the future will automatically install the above involved more than the completion of the preliminary work tool library
The second step
Orm start a new model called the object model is to give the same field in src -main-java in a new package com.itheima-domain
Built inside a class user
A detailed model code is as follows:
1 package com.itheima.domain; 2 3 import java.io.Serializable; 4 import java.util.Date; 5 6 public class User implements Serializable { 7 private Integer id; 8 private String username; 9 private Date birthday; 10 private String sex; 11 private String address; 12 13 public Integer getId() { 14 return id; 15 } 16 17 public void setId(Integer id) { 18 this.id = id; 19 } 20 21 public String getUsername() { 22 return username; 23 } 24 25 public void setUsername(String username) { 26 this.username = username; 27 } 28 29 public Date getBirthday() { 30 return birthday; 31 } 32 33 public void setBirthday(Date birthday) { 34 this.birthday = birthday; 35 } 36 37 public String getSex() { 38 return sex; 39 } 40 41 public void setSex(String sex) { 42 this.sex = sex; 43 } 44 45 public String getAddress() { 46 return address; 47 } 48 49 public void setAddress(String address) { 50 this.address = address; 51 } 52 53 @Override 54 public String toString() { 55 return "User{" + 56 "id=" + id + 57 ", username='" + username + '\'' + 58 ", birthday=" + birthday + 59 ", sex='" + sex + '\'' + 60 ", address='" + address + '\'' + 61 '}'; 62 } 63 }
Then configure the primary configuration, databases and resources
The main configuration file as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!--主配置--> <environments default="mysql"> <environment id="mysql"> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/eesy"/> <property name="username" value="root"/> <property name="password" value="142857"/> </dataSource> </environment> </environments> <!--yanse--> <mappers> <mapper resource="com/itheima/dao/IUserDao.xml"/> </mappers> </configuration>