Skip to content

Commit

Permalink
createIfNotExistsTable
Browse files Browse the repository at this point in the history
  • Loading branch information
javahongxi committed Feb 5, 2018
1 parent 4ebd7cb commit 305c194
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Expand Up @@ -7,6 +7,8 @@
*/
public interface UserDao {

void createIfNotExistsTable();

User findByUsername(String username);

void insert(User user);
Expand Down
Expand Up @@ -7,6 +7,11 @@
* Created by javahongxi on 2017/12/24.
*/
public class UserDaoImpl extends BaseDao implements UserDao {
@Override
public void createIfNotExistsTable() {
this.sqlSession.update("User.createIfNotExistsTable");
}

@Override
public User findByUsername(String username) {
return this.sqlSession.selectOne("User.findByUsername", username);
Expand Down
Expand Up @@ -2,6 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="User">

<update id="createIfNotExistsTable">
CREATE TABLE IF NOT EXISTS user (id BIGINT AUTO_INCREMENT, username VARCHAR(20) NOT NULL, nickname VARCHAR(20), gender TINYINT, age INT, create_date DATETIME, update_date DATETIME, PRIMARY KEY (id));
</update>

<select id="findByUsername" parameterType="string" resultType="User">
select * from user where username = #username#
</select>
Expand Down
Expand Up @@ -20,6 +20,7 @@ public User findByUsername(String username) {

@Override
public void add(User user) {
userDao.createIfNotExistsTable(); // test
userDao.insert(user);
}

Expand Down

0 comments on commit 305c194

Please sign in to comment.