V. Setting up the environment: auxiliary functions
@
- V. Setting up the environment: auxiliary functions
- Writing Login Failure Exceptions
- Writing Constant Classes
- MD5 Tools (Encryption Tools category)
- Logging Profiles
Writing Login Failure Exceptions
We are indemo-module04-util
Under Modules, create a module named:package, create an exception class named: LoginFailedException --> as the login exception handler.
package ;
public class LoginFailedException extends RuntimeException {
public LoginFailedException() {
}
public LoginFailedException(String message) {
super(message);
}
public LoginFailedException(String message, Throwable cause) {
super(message, cause);
}
public LoginFailedException(Throwable cause) {
super(cause);
}
public LoginFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Writing Constant Classes
We are indemo-module04-util
Under Modules, create a module named:package, create a class named: ImperialCourtConst class - > as a constant class that defines some constant information needed in our project.
package ;
public class ImperialCourtConst {
public static final String LOGIN_FAILED_MESSAGE = "username、incorrect password,can't go to the palace!";
public static final String ACCESS_DENIED_MESSAGE = "forbidden place during the palace palace exam (idiom); fig. women's palace,not be allowed to trespass!";
public static final String LOGIN_EMP_ATTR_NAME = "loginInfo";
}
MD5 Tools (Encryption Tools category)
We are indemo-module04-util
Under Modules, create a module named:Under the package "MD5Util", create a class named: MD5Util class --> as a tool class that defines some of the tool methods needed in our project.
package ;
import ;
import ;
import ;
public class MD5Util {
/**
* Execute against plaintext stringsMD5encrypted
*
* @param source
* @return
*/
public static String encode(String source) {
// 1.Determine if a plaintext string is valid
if (source == null || "".equals(source)) {
throw new RuntimeException("用于encrypted的明文不可为空");
}
// 2.Declare the name of the algorithm
String algorithm = "md5";
// 3.gainMessageDigestboyfriend
MessageDigest messageDigest = null;
try {
messageDigest = (algorithm);
} catch (NoSuchAlgorithmException e) {
();
}
// 4.gain明文字符串对应的字节数组
byte[] input = ();
// 5.执行encrypted
byte[] output = (input);
// 6.establishBigIntegerboyfriend
int signum = 1;
BigInteger bigInteger = new BigInteger(signum, output);
// 7.on the basis of16binary system willbigIntegerto a string
int radix = 16;
String encoded = (radix).toUpperCase();
return encoded;
}
}
Logging Profiles
at that
demo-module01-web
module, under the src/main/resources root path, create a file namedThe logging configuration file for theNote: The filename is the name of the
It can't be anything else. It has to be this. 。
<?xml version="1.0" encoding="UTF-8"? >;xml version="1.0" encoding="UTF-8"?
<configuration debug="true">!
<! -- Specify the location of the log output -- > <!
<appender name="STDOUT"
class=""> <appender name="STDOUT
<encoder>.
<! -- Format of the log output -->
<! -- In order: time, log level, thread name, class to print the log, contents of the log body, newlines --> <!
<pattern>[%d{HH:mm:}] [%-5level] [%thread] [%logger] [%msg]%n</pattern>
<charset>UTF-8</charset>
</encoder>.
</appender>.
<! -- Set the global log level. The log levels are, in order, DEBUG, INFO, WARN, and ERROR -->.
<! -- Specifies that any log level prints only the logs of the current level and subsequent levels. -->
< root level="INFO">
<! -- Specify the appender to print the logs, here the previously configured appender is referenced by "STDOUT" --> <appender-ref
<appender-ref ref="STDOUT" />;
</root>
<! -- Specify a logging level specifically for a particular package -->
<logger name="" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
</configuration>
Corresponding to the previous section in the sequence: ✏️✏️✏️Four, build the environment: expression layer - CSDN Blogs
The corresponding sequence is the next section: ✏️✏️✏️