其代码为:
\lstset{
inputencoding=utf8/latin1,
language=Java, % choose the language of the code
numbers=left, % where to put the line-numbers
stepnumber=1, % the step between two line-numbers.
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
keepspaces=true,
basicstyle=\footnotesize\ttfamily,
commentstyle=\color{greencomments},
keywordstyle=\color{bluekeywords},
stringstyle=\color{redstrings},
identifierstyle=\color{types},
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=true, % sets if automatic breaks should only happen at whitespace
}
\begin{lstlisting}
@Override
public boolean login(@NotNull Account account)
throws IOException, InterruptedException {
if (account.getEmail() == null)
return false;
if (account.getPassword() == null)
return false;
if (!respectPattern(String.valueOf(account.getPassword())))
return false;
String URL = getBaseUrl();
URL = URL.concat("/" + REPOSITORY);
URL = URL.concat("/admin-login");
final Map<String, Object> values = new HashMap<>();
values.put("key", account.getEmail());
values.put("password", String.valueOf(account.getPassword()));
ObjectMapper objectMapper = ObjectMapperCreator.getNewObjectMapper();
String requestBody = objectMapper.writeValueAsString(values);
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest request = HttpRequest
.newBuilder()
.uri(URI.create(URL))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse<String> response = httpClient.send(request,
HttpResponse.BodyHandlers.ofString());
return response.statusCode() == 200 &&
setAuthenticationResultIntoAccount(response, account);
}
\end{lstlisting}
我怎样才能将颜色更改为默认的 Java 颜色并让其自动缩进?
答案1
没有“默认 Java 颜色”。如果您不喜欢颜色,则必须手动更改颜色。例如,尝试切换
keywordstyle=\color{black}
或者定义你自己的颜色:
\definecolor{mauve}{rgb}{0.3,0,0.3}
然后
keywordstyle=\color{mauve}