-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kaijun
committed
Nov 17, 2021
1 parent
b6e2107
commit 003a112
Showing
9 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.demo.mapper; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
import com.example.demo.entity.County; | ||
|
||
@Mapper | ||
public interface CountyMapper { | ||
|
||
@Select(" SELECT " | ||
+ " ID, NAME " | ||
+ " FROM " | ||
+ " test_project.county ") | ||
public List<County> findAllCounty(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.demo.mapper; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Select; | ||
|
||
import com.example.demo.entity.District; | ||
|
||
@Mapper | ||
public interface DistrictMapper { | ||
|
||
@Select(" SELECT " | ||
+ " ID, NAME " | ||
+ " FROM " | ||
+ " test_project.district " | ||
+ " WHERE " | ||
+ " C_ID = #{c_id} ") | ||
public List<District> findDistrictByC_id(String c_id); | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/example/demo/mapper/MemberAccountMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.demo.mapper; | ||
|
||
import org.apache.ibatis.annotations.Insert; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Select; | ||
import org.apache.ibatis.annotations.Update; | ||
|
||
import com.example.demo.entity.MemberAccount; | ||
|
||
@Mapper | ||
public interface MemberAccountMapper { | ||
|
||
@Insert(" INSERT INTO test_project.member_account ( " | ||
+ " USERNAME, PASSWORD, SALT, " | ||
+ " CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME " | ||
+ " ) " | ||
+ " VALUE ( " | ||
+ " #{username}, #{password}, #{salt}, " | ||
+ " #{create_by}, NOW(), #{update_by}, NOW() " | ||
+ " ) ") | ||
public Integer insert(MemberAccount memberAccount); | ||
|
||
@Select(" SELECT " | ||
+ " ID, USERNAME, PASSWORD, SALT " | ||
+ " FROM " | ||
+ " test_project.member_account " | ||
+ " WHERE " | ||
+ " USERNAME = #{username} ") | ||
public MemberAccount findMemberAccountByUsername(String username); | ||
|
||
@Update(" UPDATE " | ||
+ " test_project.member_account " | ||
+ " SET " | ||
+ " PASSWORD = #{password}, UPDATE_BY = #{update_by}, UPDATE_TIME = NOW() " | ||
+ " WHERE " | ||
+ " ID = #{id} ") | ||
public Integer update(MemberAccount memberAccount); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.demo.mapper; | ||
|
||
import org.apache.ibatis.annotations.Insert; | ||
import org.apache.ibatis.annotations.Mapper; | ||
import org.apache.ibatis.annotations.Select; | ||
import org.apache.ibatis.annotations.Update; | ||
|
||
import com.example.demo.entity.Member; | ||
|
||
@Mapper | ||
public interface MemberMapper { | ||
|
||
@Insert(" INSERT INTO test_project.member ( " | ||
+ " MA_ID, NAME, ID_NUMBER, BIRTHDAY, " | ||
+ " PHONE, C_ID, D_ID, ADDRESS, " | ||
+ " CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME " | ||
+ " ) " | ||
+ " VALUE ( " | ||
+ " #{ma_id}, #{name}, #{id_number}, #{birthday}, " | ||
+ " #{phone}, #{c_id}, #{d_id}, #{address}, " | ||
+ " #{create_by}, NOW(), #{update_by}, NOW() " | ||
+ " ) ") | ||
public Integer insert(Member member); | ||
|
||
@Select(" SELECT " | ||
+ " MA_ID, NAME, ID_NUMBER, BIRTHDAY, " | ||
+ " PHONE, C_ID, D_ID, ADDRESS " | ||
+ " FROM " | ||
+ " test_project.member " | ||
+ " WHERE " | ||
+ " MA_ID = #{ma_id} ") | ||
public Member findMemberByMa_id(String ma_id); | ||
|
||
@Update(" UPDATE " | ||
+ " test_project.member " | ||
+ " SET " | ||
+ " ID_NUMBER = #{id_number}, BIRTHDAY = #{birthday}, PHONE = #{phone}, " | ||
+ " C_ID = #{c_id}, D_ID = #{d_id}, ADDRESS = #{address}, " | ||
+ " UPDATE_BY = #{update_by}, UPDATE_TIME = NOW() " | ||
+ " WHERE " | ||
+ " MA_ID = #{ma_id} ") | ||
public Integer update(Member member); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/com/example/demo/mapper/CountyMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.demo.mapper; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import com.example.demo.entity.County; | ||
|
||
@SpringBootTest | ||
public class CountyMapperTest { | ||
|
||
@Autowired | ||
private CountyMapper countyMapper; | ||
|
||
@Test | ||
public void findAllCounty() { | ||
List<County> list = countyMapper.findAllCounty(); | ||
if(list != null) list.forEach(county -> System.out.println(county)); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/com/example/demo/mapper/DistrictMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.demo.mapper; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import com.example.demo.entity.District; | ||
|
||
@SpringBootTest | ||
public class DistrictMapperTest { | ||
|
||
@Autowired | ||
private DistrictMapper districtMapper; | ||
|
||
@Test | ||
public void findDistrictByC_id() { | ||
String c_id = "1"; | ||
List<District> list = districtMapper.findDistrictByC_id(c_id); | ||
if(list != null) list.forEach(district -> System.out.println(district)); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/example/demo/mapper/MemberAccountMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.example.demo.mapper; | ||
|
||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import com.example.demo.entity.MemberAccount; | ||
|
||
@SpringBootTest | ||
public class MemberAccountMapperTest { | ||
|
||
@Autowired | ||
private MemberAccountMapper memberAccountMapper; | ||
|
||
@Test | ||
public void insert() { | ||
MemberAccount memberAccount = new MemberAccount(); | ||
memberAccount.setUsername("username@email.com"); | ||
memberAccount.setPassword("password"); | ||
|
||
String salt = UUID.randomUUID().toString().toUpperCase().replaceAll("-", ""); | ||
memberAccount.setSalt(salt); | ||
memberAccount.setCreate_by(memberAccount.getUsername()); | ||
memberAccount.setUpdate_by(memberAccount.getUsername()); | ||
|
||
Integer id = memberAccountMapper.insert(memberAccount); | ||
System.out.println(id); | ||
} | ||
|
||
@Test | ||
public void findMemberAccountByUsername() { | ||
String username = "username@email.com"; | ||
MemberAccount memberAccount = memberAccountMapper.findMemberAccountByUsername(username); | ||
if(memberAccount != null) System.out.println(memberAccount.toString()); | ||
} | ||
|
||
@Test | ||
public void update() { | ||
MemberAccount memberAccount = new MemberAccount(); | ||
memberAccount.setId("1"); | ||
memberAccount.setPassword("123456"); | ||
memberAccount.setUpdate_by("username@email.com"); | ||
|
||
Integer result = memberAccountMapper.update(memberAccount); | ||
System.out.println(result); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/example/demo/mapper/MemberMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.example.demo.mapper; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import com.example.demo.entity.Member; | ||
|
||
@SpringBootTest | ||
public class MemberMapperTest { | ||
|
||
@Autowired | ||
private MemberMapper memberMapper; | ||
|
||
@Test | ||
public void insert() { | ||
Member member = new Member(); | ||
member.setMa_id("1"); | ||
member.setName("測試"); | ||
member.setId_number("A123456789"); | ||
member.setBirthday("1990-01-01"); | ||
member.setPhone("0987654321"); | ||
member.setC_id("1"); | ||
member.setD_id("1"); | ||
member.setAddress("地址"); | ||
member.setCreate_by("username@email.com"); | ||
member.setUpdate_by("username@email.com"); | ||
|
||
Integer result = memberMapper.insert(member); | ||
System.out.println(result); | ||
} | ||
|
||
@Test | ||
public void findMemberByMa_id() { | ||
Member member = memberMapper.findMemberByMa_id("1"); | ||
if(member != null) System.out.println(member.toString()); | ||
} | ||
|
||
@Test | ||
public void update() { | ||
Member member = new Member(); | ||
member.setMa_id("1"); | ||
member.setId_number("A123456789"); | ||
member.setBirthday("2000-01-01"); | ||
member.setPhone("0987654321"); | ||
member.setC_id("2"); | ||
member.setD_id("2"); | ||
member.setAddress("地址"); | ||
member.setUpdate_by("username@email.com"); | ||
|
||
Integer result = memberMapper.update(member); | ||
System.out.println(result); | ||
} | ||
|
||
} |