Commit a5c2aff4 authored by Junling Bu's avatar Junling Bu
Browse files

chore[后端服务]: 后端服务代码基于IDEA的reformat code工具格式化代码,但是mybatis generator生成的代码除外。

parent 556f269d
...@@ -59,16 +59,18 @@ import java.security.SecureRandom; ...@@ -59,16 +59,18 @@ import java.security.SecureRandom;
public class BCrypt { public class BCrypt {
// BCrypt parameters // BCrypt parameters
static final int MIN_LOG_ROUNDS = 4;
static final int MAX_LOG_ROUNDS = 31;
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10; private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
private static final int BCRYPT_SALT_LEN = 16; private static final int BCRYPT_SALT_LEN = 16;
// Blowfish parameters // Blowfish parameters
private static final int BLOWFISH_NUM_ROUNDS = 16; private static final int BLOWFISH_NUM_ROUNDS = 16;
// Initial contents of key schedule // Initial contents of key schedule
private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, private static final int P_orig[] = {0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377,
0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
0x9216d5d9, 0x8979fb1b }; 0x9216d5d9, 0x8979fb1b};
private static final int S_orig[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, private static final int S_orig[] = {0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7,
0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5,
...@@ -238,26 +240,24 @@ public class BCrypt { ...@@ -238,26 +240,24 @@ public class BCrypt {
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76,
0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0,
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 }; 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6};
// bcrypt IV: "OrpheanBeholderScryDoubt" // bcrypt IV: "OrpheanBeholderScryDoubt"
static private final int bf_crypt_ciphertext[] = { 0x4f727068, 0x65616e42, static private final int bf_crypt_ciphertext[] = {0x4f727068, 0x65616e42,
0x65686f6c, 0x64657253, 0x63727944, 0x6f756274 }; 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274};
// Table for Base64 encoding // Table for Base64 encoding
static private final char base64_code[] = { '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', static private final char base64_code[] = {'.', '/', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
// Table for Base64 decoding // Table for Base64 decoding
static private final byte index_64[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, static private final byte index_64[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -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, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
-1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1 }; 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1};
static final int MIN_LOG_ROUNDS = 4;
static final int MAX_LOG_ROUNDS = 31;
// Expanded Blowfish key // Expanded Blowfish key
private int P[]; private int P[];
private int S[]; private int S[];
...@@ -267,10 +267,10 @@ public class BCrypt { ...@@ -267,10 +267,10 @@ public class BCrypt {
* that this is <strong>not</strong> compatible with the standard MIME-base64 * that this is <strong>not</strong> compatible with the standard MIME-base64
* encoding. * encoding.
* *
* @param d the byte array to encode * @param d the byte array to encode
* @param len the number of bytes to encode * @param len the number of bytes to encode
* @param rs the destination buffer for the base64-encoded string * @param rs the destination buffer for the base64-encoded string
* @exception IllegalArgumentException if the length is invalid * @throws IllegalArgumentException if the length is invalid
*/ */
static void encode_base64(byte d[], int len, StringBuilder rs) static void encode_base64(byte d[], int len, StringBuilder rs)
throws IllegalArgumentException { throws IllegalArgumentException {
...@@ -307,6 +307,7 @@ public class BCrypt { ...@@ -307,6 +307,7 @@ public class BCrypt {
/** /**
* Look up the 3 bits base64-encoded by the specified character, range-checking * Look up the 3 bits base64-encoded by the specified character, range-checking
* against conversion table * against conversion table
*
* @param x the base64-encoded value * @param x the base64-encoded value
* @return the decoded value of x * @return the decoded value of x
*/ */
...@@ -320,7 +321,8 @@ public class BCrypt { ...@@ -320,7 +321,8 @@ public class BCrypt {
/** /**
* Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that * Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that
* this is *not* compatible with the standard MIME-base64 encoding. * this is *not* compatible with the standard MIME-base64 encoding.
* @param s the string to decode *
* @param s the string to decode
* @param maxolen the maximum number of bytes to decode * @param maxolen the maximum number of bytes to decode
* @return an array containing the decoded bytes * @return an array containing the decoded bytes
* @throws IllegalArgumentException if maxolen is invalid * @throws IllegalArgumentException if maxolen is invalid
...@@ -366,36 +368,9 @@ public class BCrypt { ...@@ -366,36 +368,9 @@ public class BCrypt {
return out.toByteArray(); return out.toByteArray();
} }
/**
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
* @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks
*/
private final void encipher(int lr[], int off) {
int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0];
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) {
// Feistel substitution on left word
n = S[(l >> 24) & 0xff];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[++i];
// Feistel substitution on right word
n = S[(r >> 24) & 0xff];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[++i];
}
lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1];
lr[off + 1] = l;
}
/** /**
* Cycically extract a word of key material * Cycically extract a word of key material
*
* @param data the string to extract the data from * @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the current offset into data * @param offp a "pointer" (as a one-entry array) to the current offset into data
* @return the next word of material from data * @return the next word of material from data
...@@ -414,74 +389,6 @@ public class BCrypt { ...@@ -414,74 +389,6 @@ public class BCrypt {
return word; return word;
} }
/**
* Initialise the Blowfish key schedule
*/
private void init_key() {
P = (int[]) P_orig.clone();
S = (int[]) S_orig.clone();
}
/**
* Key the Blowfish cipher
* @param key an array containing the key
*/
private void key(byte key[]) {
int i;
int koffp[] = { 0 };
int lr[] = { 0, 0 };
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
/**
* Perform the "enhanced key schedule" step described by Provos and Mazieres in
* "A Future-Adaptable Password Scheme" http://www.openbsd.org/papers/bcrypt-paper.ps
* @param data salt information
* @param key password information
*/
private void ekskey(byte data[], byte key[]) {
int i;
int koffp[] = { 0 }, doffp[] = { 0 };
int lr[] = { 0, 0 };
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
static long roundsForLogRounds(int log_rounds) { static long roundsForLogRounds(int log_rounds) {
if (log_rounds < 4 || log_rounds > 31) { if (log_rounds < 4 || log_rounds > 31) {
throw new IllegalArgumentException("Bad number of rounds"); throw new IllegalArgumentException("Bad number of rounds");
...@@ -489,47 +396,11 @@ public class BCrypt { ...@@ -489,47 +396,11 @@ public class BCrypt {
return 1L << log_rounds; return 1L << log_rounds;
} }
/**
* Perform the central password hashing step in the bcrypt scheme
* @param password the password to hash
* @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number of rounds of hashing to apply
* @return an array containing the binary hashed password
*/
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
int cdata[] = (int[]) bf_crypt_ciphertext.clone();
int clen = cdata.length;
byte ret[];
long rounds = roundsForLogRounds(log_rounds);
init_key();
ekskey(salt, password);
for (long i = 0; i < rounds; i++) {
key(password);
key(salt);
}
for (int i = 0; i < 64; i++) {
for (int j = 0; j < (clen >> 1); j++) {
encipher(cdata, j << 1);
}
}
ret = new byte[clen * 4];
for (int i = 0, j = 0; i < clen; i++) {
ret[j++] = (byte) ((cdata[i] >> 24) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 16) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 8) & 0xff);
ret[j++] = (byte) (cdata[i] & 0xff);
}
return ret;
}
/** /**
* Hash a password using the OpenBSD bcrypt scheme * Hash a password using the OpenBSD bcrypt scheme
*
* @param password the password to hash * @param password the password to hash
* @param salt the salt to hash with (perhaps generated using BCrypt.gensalt) * @param salt the salt to hash with (perhaps generated using BCrypt.gensalt)
* @return the hashed password * @return the hashed password
* @throws IllegalArgumentException if invalid salt is passed * @throws IllegalArgumentException if invalid salt is passed
*/ */
...@@ -556,8 +427,7 @@ public class BCrypt { ...@@ -556,8 +427,7 @@ public class BCrypt {
} }
if (salt.charAt(2) == '$') { if (salt.charAt(2) == '$') {
off = 3; off = 3;
} } else {
else {
minor = salt.charAt(2); minor = salt.charAt(2);
if (minor != 'a' || salt.charAt(3) != '$') { if (minor != 'a' || salt.charAt(3) != '$') {
throw new IllegalArgumentException("Invalid salt revision"); throw new IllegalArgumentException("Invalid salt revision");
...@@ -578,8 +448,7 @@ public class BCrypt { ...@@ -578,8 +448,7 @@ public class BCrypt {
real_salt = salt.substring(off + 3, off + 25); real_salt = salt.substring(off + 3, off + 25);
try { try {
passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8"); passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8");
} } catch (UnsupportedEncodingException uee) {
catch (UnsupportedEncodingException uee) {
throw new AssertionError("UTF-8 is not supported"); throw new AssertionError("UTF-8 is not supported");
} }
...@@ -605,9 +474,10 @@ public class BCrypt { ...@@ -605,9 +474,10 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method * Generate a salt for use with the BCrypt.hashpw() method
*
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work * @param log_rounds the log2 of the number of rounds of hashing to apply - the work
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31. * factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
* @param random an instance of SecureRandom to use * @param random an instance of SecureRandom to use
* @return an encoded salt value * @return an encoded salt value
*/ */
public static String gensalt(int log_rounds, SecureRandom random) { public static String gensalt(int log_rounds, SecureRandom random) {
...@@ -631,8 +501,9 @@ public class BCrypt { ...@@ -631,8 +501,9 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method * Generate a salt for use with the BCrypt.hashpw() method
*
* @param log_rounds the log2 of the number of rounds of hashing to apply - the work * @param log_rounds the log2 of the number of rounds of hashing to apply - the work
* factor therefore increases as 2**log_rounds. Minimum 4, maximum 31. * factor therefore increases as 2**log_rounds. Minimum 4, maximum 31.
* @return an encoded salt value * @return an encoded salt value
*/ */
public static String gensalt(int log_rounds) { public static String gensalt(int log_rounds) {
...@@ -642,6 +513,7 @@ public class BCrypt { ...@@ -642,6 +513,7 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable * Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable
* default for the number of hashing rounds to apply * default for the number of hashing rounds to apply
*
* @return an encoded salt value * @return an encoded salt value
*/ */
public static String gensalt() { public static String gensalt() {
...@@ -650,8 +522,9 @@ public class BCrypt { ...@@ -650,8 +522,9 @@ public class BCrypt {
/** /**
* Check that a plaintext password matches a previously hashed one * Check that a plaintext password matches a previously hashed one
*
* @param plaintext the plaintext password to verify * @param plaintext the plaintext password to verify
* @param hashed the previously-hashed password * @param hashed the previously-hashed password
* @return true if the passwords match, false otherwise * @return true if the passwords match, false otherwise
*/ */
public static boolean checkpw(String plaintext, String hashed) { public static boolean checkpw(String plaintext, String hashed) {
...@@ -672,4 +545,141 @@ public class BCrypt { ...@@ -672,4 +545,141 @@ public class BCrypt {
} }
return ret == 0; return ret == 0;
} }
/**
* Blowfish encipher a single 64-bit block encoded as two 32-bit halves
*
* @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks
*/
private final void encipher(int lr[], int off) {
int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0];
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) {
// Feistel substitution on left word
n = S[(l >> 24) & 0xff];
n += S[0x100 | ((l >> 16) & 0xff)];
n ^= S[0x200 | ((l >> 8) & 0xff)];
n += S[0x300 | (l & 0xff)];
r ^= n ^ P[++i];
// Feistel substitution on right word
n = S[(r >> 24) & 0xff];
n += S[0x100 | ((r >> 16) & 0xff)];
n ^= S[0x200 | ((r >> 8) & 0xff)];
n += S[0x300 | (r & 0xff)];
l ^= n ^ P[++i];
}
lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1];
lr[off + 1] = l;
}
/**
* Initialise the Blowfish key schedule
*/
private void init_key() {
P = (int[]) P_orig.clone();
S = (int[]) S_orig.clone();
}
/**
* Key the Blowfish cipher
*
* @param key an array containing the key
*/
private void key(byte key[]) {
int i;
int koffp[] = {0};
int lr[] = {0, 0};
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
/**
* Perform the "enhanced key schedule" step described by Provos and Mazieres in
* "A Future-Adaptable Password Scheme" http://www.openbsd.org/papers/bcrypt-paper.ps
*
* @param data salt information
* @param key password information
*/
private void ekskey(byte data[], byte key[]) {
int i;
int koffp[] = {0}, doffp[] = {0};
int lr[] = {0, 0};
int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) {
P[i] = P[i] ^ streamtoword(key, koffp);
}
for (i = 0; i < plen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
P[i] = lr[0];
P[i + 1] = lr[1];
}
for (i = 0; i < slen; i += 2) {
lr[0] ^= streamtoword(data, doffp);
lr[1] ^= streamtoword(data, doffp);
encipher(lr, 0);
S[i] = lr[0];
S[i + 1] = lr[1];
}
}
/**
* Perform the central password hashing step in the bcrypt scheme
*
* @param password the password to hash
* @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number of rounds of hashing to apply
* @return an array containing the binary hashed password
*/
private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
int cdata[] = (int[]) bf_crypt_ciphertext.clone();
int clen = cdata.length;
byte ret[];
long rounds = roundsForLogRounds(log_rounds);
init_key();
ekskey(salt, password);
for (long i = 0; i < rounds; i++) {
key(password);
key(salt);
}
for (int i = 0; i < 64; i++) {
for (int j = 0; j < (clen >> 1); j++) {
encipher(cdata, j << 1);
}
}
ret = new byte[clen * 4];
for (int i = 0, j = 0; i < clen; i++) {
ret[j++] = (byte) ((cdata[i] >> 24) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 16) & 0xff);
ret[j++] = (byte) ((cdata[i] >> 8) & 0xff);
ret[j++] = (byte) (cdata[i] & 0xff);
}
return ret;
}
} }
\ No newline at end of file
...@@ -28,16 +28,13 @@ import java.util.regex.Pattern; ...@@ -28,16 +28,13 @@ import java.util.regex.Pattern;
* (exponentially) to hash the passwords. The default value is 10. * (exponentially) to hash the passwords. The default value is 10.
* *
* @author Dave Syer * @author Dave Syer
*
*/ */
public class BCryptPasswordEncoder { public class BCryptPasswordEncoder {
private Pattern BCRYPT_PATTERN = Pattern
.compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}");
private final Log logger = LogFactory.getLog(getClass()); private final Log logger = LogFactory.getLog(getClass());
private final int strength; private final int strength;
private final SecureRandom random; private final SecureRandom random;
private Pattern BCRYPT_PATTERN = Pattern
.compile("\\A\\$2a?\\$\\d\\d\\$[./0-9A-Za-z]{53}");
public BCryptPasswordEncoder() { public BCryptPasswordEncoder() {
this(-1); this(-1);
...@@ -52,8 +49,7 @@ public class BCryptPasswordEncoder { ...@@ -52,8 +49,7 @@ public class BCryptPasswordEncoder {
/** /**
* @param strength the log rounds to use, between 4 and 31 * @param strength the log rounds to use, between 4 and 31
* @param random the secure random instance to use * @param random the secure random instance to use
*
*/ */
public BCryptPasswordEncoder(int strength, SecureRandom random) { public BCryptPasswordEncoder(int strength, SecureRandom random) {
if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) { if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) {
...@@ -68,12 +64,10 @@ public class BCryptPasswordEncoder { ...@@ -68,12 +64,10 @@ public class BCryptPasswordEncoder {
if (strength > 0) { if (strength > 0) {
if (random != null) { if (random != null) {
salt = BCrypt.gensalt(strength, random); salt = BCrypt.gensalt(strength, random);
} } else {
else {
salt = BCrypt.gensalt(strength); salt = BCrypt.gensalt(strength);
} }
} } else {
else {
salt = BCrypt.gensalt(); salt = BCrypt.gensalt();
} }
return BCrypt.hashpw(rawPassword.toString(), salt); return BCrypt.hashpw(rawPassword.toString(), salt);
......
...@@ -9,12 +9,13 @@ import java.lang.annotation.Target; ...@@ -9,12 +9,13 @@ import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*; import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({ METHOD, FIELD, PARAMETER }) @Target({METHOD, FIELD, PARAMETER})
@Retention(RUNTIME) @Retention(RUNTIME)
@Documented @Documented
@Constraint(validatedBy = OrderValidator.class) @Constraint(validatedBy = OrderValidator.class)
public @interface Order { public @interface Order {
String message() default "排序类型不支持"; String message() default "排序类型不支持";
String[] accepts() default {"desc", "asc"}; String[] accepts() default {"desc", "asc"};
Class<?>[] groups() default {}; Class<?>[] groups() default {};
......
...@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext; ...@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class OrderValidator implements ConstraintValidator<Order, String>{ public class OrderValidator implements ConstraintValidator<Order, String> {
private List<String> valueList; private List<String> valueList;
@Override @Override
public void initialize(Order order) { public void initialize(Order order) {
valueList = new ArrayList<String>(); valueList = new ArrayList<String>();
for(String val : order.accepts()) { for (String val : order.accepts()) {
valueList.add(val.toUpperCase()); valueList.add(val.toUpperCase());
} }
} }
@Override @Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if(!valueList.contains(s.toUpperCase())) { if (!valueList.contains(s.toUpperCase())) {
return false; return false;
} }
return true; return true;
......
...@@ -9,12 +9,13 @@ import java.lang.annotation.Target; ...@@ -9,12 +9,13 @@ import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*; import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({ METHOD, FIELD, PARAMETER }) @Target({METHOD, FIELD, PARAMETER})
@Retention(RUNTIME) @Retention(RUNTIME)
@Documented @Documented
@Constraint(validatedBy = SortValidator.class) @Constraint(validatedBy = SortValidator.class)
public @interface Sort { public @interface Sort {
String message() default "排序字段不支持"; String message() default "排序字段不支持";
String[] accepts() default {"add_time", "id"}; String[] accepts() default {"add_time", "id"};
Class<?>[] groups() default {}; Class<?>[] groups() default {};
......
...@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext; ...@@ -5,20 +5,20 @@ import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class SortValidator implements ConstraintValidator<Sort, String>{ public class SortValidator implements ConstraintValidator<Sort, String> {
private List<String> valueList; private List<String> valueList;
@Override @Override
public void initialize(Sort sort) { public void initialize(Sort sort) {
valueList = new ArrayList<String>(); valueList = new ArrayList<String>();
for(String val : sort.accepts()) { for (String val : sort.accepts()) {
valueList.add(val.toUpperCase()); valueList.add(val.toUpperCase());
} }
} }
@Override @Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if(!valueList.contains(s.toUpperCase())) { if (!valueList.contains(s.toUpperCase())) {
return false; return false;
} }
return true; return true;
......
...@@ -6,10 +6,8 @@ import org.linlinjava.litemall.core.storage.AliyunStorage; ...@@ -6,10 +6,8 @@ import org.linlinjava.litemall.core.storage.AliyunStorage;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.util.FileCopyUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
......
...@@ -9,14 +9,14 @@ import org.springframework.test.context.web.WebAppConfiguration; ...@@ -9,14 +9,14 @@ import org.springframework.test.context.web.WebAppConfiguration;
/** /**
* 异步测试 * 异步测试
*
*/ */
@WebAppConfiguration @WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class AsyncTest { public class AsyncTest {
@Autowired AsyncTask task; @Autowired
AsyncTask task;
@Test @Test
public void test() { public void test() {
......
...@@ -8,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest; ...@@ -8,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
......
...@@ -17,19 +17,27 @@ import java.util.concurrent.Executor; ...@@ -17,19 +17,27 @@ import java.util.concurrent.Executor;
/** /**
* 测试邮件发送服务 * 测试邮件发送服务
* * <p>
* 注意LitemallNotifyService采用异步线程操作 * 注意LitemallNotifyService采用异步线程操作
* 因此测试的时候需要睡眠一会儿,保证任务执行 * 因此测试的时候需要睡眠一会儿,保证任务执行
* * <p>
* 开发者需要确保: * 开发者需要确保:
* 1. 在相应的邮件服务器设置正确notify.properties已经设置正确 * 1. 在相应的邮件服务器设置正确notify.properties已经设置正确
* 2. 在相应的邮件服务器设置正确 * 2. 在相应的邮件服务器设置正确
*/ */
@WebAppConfiguration @WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest @SpringBootTest
public class MailTest { public class MailTest {
@Autowired
private NotifyService notifyService;
@Test
public void testMail() {
notifyService.notifyMail("订单信息", "订单1111111已付款,请发货");
}
@Configuration @Configuration
@Import(Application.class) @Import(Application.class)
static class ContextConfiguration { static class ContextConfiguration {
...@@ -40,13 +48,5 @@ public class MailTest { ...@@ -40,13 +48,5 @@ public class MailTest {
} }
} }
@Autowired
private NotifyService notifyService;
@Test
public void testMail() {
notifyService.notifyMail("订单信息", "订单1111111已付款,请发货");
}
} }
...@@ -18,10 +18,10 @@ import java.util.concurrent.Executor; ...@@ -18,10 +18,10 @@ import java.util.concurrent.Executor;
/** /**
* 测试短信发送服务 * 测试短信发送服务
* * <p>
* 注意LitemallNotifyService采用异步线程操作 * 注意LitemallNotifyService采用异步线程操作
* 因此测试的时候需要睡眠一会儿,保证任务执行 * 因此测试的时候需要睡眠一会儿,保证任务执行
* * <p>
* 开发者需要确保: * 开发者需要确保:
* 1. 在腾讯云短信平台设置短信签名和短信模板notify.properties已经设置正确 * 1. 在腾讯云短信平台设置短信签名和短信模板notify.properties已经设置正确
* 2. 在腾讯云短信平台设置短信签名和短信模板 * 2. 在腾讯云短信平台设置短信签名和短信模板
...@@ -32,23 +32,13 @@ import java.util.concurrent.Executor; ...@@ -32,23 +32,13 @@ import java.util.concurrent.Executor;
@SpringBootTest @SpringBootTest
public class SmsTest { public class SmsTest {
@Configuration
@Import(Application.class)
static class ContextConfiguration {
@Bean
@Primary
public Executor executor() {
return new SyncTaskExecutor();
}
}
@Autowired @Autowired
private NotifyService notifyService; private NotifyService notifyService;
@Test @Test
public void testCaptcha() { public void testCaptcha() {
String phone = "xxxxxxxxxxx"; String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"}; String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.CAPTCHA, params); notifyService.notifySmsTemplate(phone, NotifyType.CAPTCHA, params);
} }
...@@ -56,7 +46,7 @@ public class SmsTest { ...@@ -56,7 +46,7 @@ public class SmsTest {
@Test @Test
public void testPaySucceed() { public void testPaySucceed() {
String phone = "xxxxxxxxxxx"; String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"}; String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.PAY_SUCCEED, params); notifyService.notifySmsTemplate(phone, NotifyType.PAY_SUCCEED, params);
} }
...@@ -64,7 +54,7 @@ public class SmsTest { ...@@ -64,7 +54,7 @@ public class SmsTest {
@Test @Test
public void testShip() { public void testShip() {
String phone = "xxxxxxxxxxx"; String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"}; String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.SHIP, params); notifyService.notifySmsTemplate(phone, NotifyType.SHIP, params);
} }
...@@ -72,8 +62,18 @@ public class SmsTest { ...@@ -72,8 +62,18 @@ public class SmsTest {
@Test @Test
public void testRefund() { public void testRefund() {
String phone = "xxxxxxxxxxx"; String phone = "xxxxxxxxxxx";
String[] params = new String[] {"123456"}; String[] params = new String[]{"123456"};
notifyService.notifySmsTemplate(phone, NotifyType.REFUND, params); notifyService.notifySmsTemplate(phone, NotifyType.REFUND, params);
} }
@Configuration
@Import(Application.class)
static class ContextConfiguration {
@Bean
@Primary
public Executor executor() {
return new SyncTaskExecutor();
}
}
} }
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<artifactId>litemall-db</artifactId> <artifactId>litemall-db</artifactId>
......
...@@ -4,8 +4,6 @@ import org.apache.ibatis.annotations.Param; ...@@ -4,8 +4,6 @@ import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.domain.LitemallOrder; import org.linlinjava.litemall.db.domain.LitemallOrder;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
public interface OrderMapper { public interface OrderMapper {
int updateWithOptimisticLocker(@Param("lastUpdateTime") LocalDateTime lastUpdateTime, @Param("order") LitemallOrder order); int updateWithOptimisticLocker(@Param("lastUpdateTime") LocalDateTime lastUpdateTime, @Param("order") LitemallOrder order);
......
...@@ -5,6 +5,8 @@ import java.util.Map; ...@@ -5,6 +5,8 @@ import java.util.Map;
public interface StatMapper { public interface StatMapper {
List<Map> statUser(); List<Map> statUser();
List<Map> statOrder(); List<Map> statOrder();
List<Map> statGoods(); List<Map> statGoods();
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ public class JsonIntegerArrayTypeHandler extends BaseTypeHandler<Integer[]> { ...@@ -17,7 +17,7 @@ public class JsonIntegerArrayTypeHandler extends BaseTypeHandler<Integer[]> {
@Override @Override
public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType) throws SQLException { public void setNonNullParameter(PreparedStatement ps, int i, Integer[] parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i,toJson(parameter)); ps.setString(i, toJson(parameter));
} }
@Override @Override
......
package org.linlinjava.litemall.db.mybatis; package org.linlinjava.litemall.db.mybatis;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/* /*
<columnOverride column="json_string" javaType="com.fasterxml.jackson.databind.JsonNode" typeHandler="JsonNodeTypeHandler"/> <columnOverride column="json_string" javaType="com.fasterxml.jackson.databind.JsonNode" typeHandler="JsonNodeTypeHandler"/>
*/ */
...@@ -19,62 +19,62 @@ public class JsonNodeTypeHandler extends BaseTypeHandler<com.fasterxml.jackson.d ...@@ -19,62 +19,62 @@ public class JsonNodeTypeHandler extends BaseTypeHandler<com.fasterxml.jackson.d
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
@Override @Override
public void setNonNullParameter(PreparedStatement ps, int i, JsonNode parameter, JdbcType jdbcType) throws SQLException { public void setNonNullParameter(PreparedStatement ps, int i, JsonNode parameter, JdbcType jdbcType) throws SQLException {
String str = null; String str = null;
try { try {
str = mapper.writeValueAsString(parameter); str = mapper.writeValueAsString(parameter);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
str = "{}"; str = "{}";
}
ps.setString(i, str);
} }
ps.setString(i, str);
}
@Override @Override
public JsonNode getNullableResult(ResultSet rs, String columnName) throws SQLException { public JsonNode getNullableResult(ResultSet rs, String columnName) throws SQLException {
String jsonSource = rs.getString(columnName); String jsonSource = rs.getString(columnName);
if(jsonSource == null){ if (jsonSource == null) {
return null;
}
try {
JsonNode jsonNode = mapper.readTree(jsonSource);
return jsonNode;
} catch (IOException e) {
e.printStackTrace();
}
return null; return null;
} }
try {
JsonNode jsonNode = mapper.readTree(jsonSource);
return jsonNode;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override @Override
public JsonNode getNullableResult(ResultSet rs, int columnIndex) throws SQLException { public JsonNode getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
String jsonSource = rs.getString(columnIndex); String jsonSource = rs.getString(columnIndex);
if(jsonSource == null){ if (jsonSource == null) {
return null;
}
try {
JsonNode jsonNode = mapper.readTree(jsonSource);
return jsonNode;
} catch (IOException e) {
e.printStackTrace();
}
return null; return null;
} }
try {
JsonNode jsonNode = mapper.readTree(jsonSource);
return jsonNode;
} catch (IOException e) {
e.printStackTrace();
}
return null;
@Override }
public JsonNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
String jsonSource = cs.getString(columnIndex); @Override
if(jsonSource == null){ public JsonNode getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
return null; String jsonSource = cs.getString(columnIndex);
} if (jsonSource == null) {
try {
JsonNode jsonNode = mapper.readTree(jsonSource);
return jsonNode;
} catch (IOException e) {
e.printStackTrace();
}
return null; return null;
} }
try {
JsonNode jsonNode = mapper.readTree(jsonSource);
return jsonNode;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
} }
\ No newline at end of file
package org.linlinjava.litemall.db.mybatis; package org.linlinjava.litemall.db.mybatis;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.JdbcType;
import java.io.IOException;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -20,13 +17,13 @@ public class JsonStringArrayTypeHandler extends BaseTypeHandler<String[]> { ...@@ -20,13 +17,13 @@ public class JsonStringArrayTypeHandler extends BaseTypeHandler<String[]> {
@Override @Override
public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType) throws SQLException { public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType) throws SQLException {
ps.setString(i,toJson(parameter)); ps.setString(i, toJson(parameter));
} }
@Override @Override
public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException { public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException {
return this.toObject(rs.getString(columnName)); return this.toObject(rs.getString(columnName));
} }
@Override @Override
public String[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException { public String[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
......
package org.linlinjava.litemall.db.service; package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallAdMapper;
import org.linlinjava.litemall.db.domain.LitemallAd; import org.linlinjava.litemall.db.domain.LitemallAd;
import org.linlinjava.litemall.db.domain.LitemallAdExample; import org.linlinjava.litemall.db.domain.LitemallAdExample;
import org.linlinjava.litemall.db.dao.LitemallAdMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
......
...@@ -60,10 +60,10 @@ public class LitemallAddressService { ...@@ -60,10 +60,10 @@ public class LitemallAddressService {
LitemallAddressExample example = new LitemallAddressExample(); LitemallAddressExample example = new LitemallAddressExample();
LitemallAddressExample.Criteria criteria = example.createCriteria(); LitemallAddressExample.Criteria criteria = example.createCriteria();
if(userId != null){ if (userId != null) {
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
} }
if(!StringUtils.isEmpty(name)){ if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%"); criteria.andNameLike("%" + name + "%");
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
...@@ -80,14 +80,14 @@ public class LitemallAddressService { ...@@ -80,14 +80,14 @@ public class LitemallAddressService {
LitemallAddressExample example = new LitemallAddressExample(); LitemallAddressExample example = new LitemallAddressExample();
LitemallAddressExample.Criteria criteria = example.createCriteria(); LitemallAddressExample.Criteria criteria = example.createCriteria();
if(userId != null){ if (userId != null) {
criteria.andUserIdEqualTo(userId); criteria.andUserIdEqualTo(userId);
} }
if(!StringUtils.isEmpty(name)){ if (!StringUtils.isEmpty(name)) {
criteria.andNameLike("%" + name + "%"); criteria.andNameLike("%" + name + "%");
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
return (int)addressMapper.countByExample(example); return (int) addressMapper.countByExample(example);
} }
} }
...@@ -14,6 +14,7 @@ import java.util.List; ...@@ -14,6 +14,7 @@ import java.util.List;
@Service @Service
public class LitemallAdminService { public class LitemallAdminService {
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
@Resource @Resource
private LitemallAdminMapper adminMapper; private LitemallAdminMapper adminMapper;
...@@ -27,12 +28,11 @@ public class LitemallAdminService { ...@@ -27,12 +28,11 @@ public class LitemallAdminService {
return adminMapper.selectByPrimaryKey(id); return adminMapper.selectByPrimaryKey(id);
} }
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
public List<LitemallAdmin> querySelective(String username, Integer page, Integer limit, String sort, String order) { public List<LitemallAdmin> querySelective(String username, Integer page, Integer limit, String sort, String order) {
LitemallAdminExample example = new LitemallAdminExample(); LitemallAdminExample example = new LitemallAdminExample();
LitemallAdminExample.Criteria criteria = example.createCriteria(); LitemallAdminExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(username)){ if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%"); criteria.andUsernameLike("%" + username + "%");
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
...@@ -40,7 +40,7 @@ public class LitemallAdminService { ...@@ -40,7 +40,7 @@ public class LitemallAdminService {
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) { if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order); example.setOrderByClause(sort + " " + order);
} }
PageHelper.startPage(page, limit); PageHelper.startPage(page, limit);
return adminMapper.selectByExampleSelective(example, result); return adminMapper.selectByExampleSelective(example, result);
} }
...@@ -49,12 +49,12 @@ public class LitemallAdminService { ...@@ -49,12 +49,12 @@ public class LitemallAdminService {
LitemallAdminExample example = new LitemallAdminExample(); LitemallAdminExample example = new LitemallAdminExample();
LitemallAdminExample.Criteria criteria = example.createCriteria(); LitemallAdminExample.Criteria criteria = example.createCriteria();
if(!StringUtils.isEmpty(username)){ if (!StringUtils.isEmpty(username)) {
criteria.andUsernameLike("%" + username + "%"); criteria.andUsernameLike("%" + username + "%");
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
return (int)adminMapper.countByExample(example); return (int) adminMapper.countByExample(example);
} }
public int updateById(LitemallAdmin admin) { public int updateById(LitemallAdmin admin) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment