我在引导程序中使用导航栏但是每当我点击其中一个页面标题时,导航栏都不会突出显示它以显示我在该页面上.例如,如果我在主页上,则导航栏如下所示:

但是,如果我点击About,我会转到"关于"页面,但导航栏仍然如下所示:

如何突出显示它所在的页面?谢谢
我有一个输入字符串,看起来像以下任何一个:
基本上字符串可以包含字母字符或数字.但它不能包含符号,只包含字母和数字.我想掩盖它,使它看起来像这样:
我到处寻找一个使用正则表达式来掩盖它的java代码示例.我在堆栈上发现了这个帖子但是假设输入纯粹是一个数字.
我调整了正则表达式以/\w(?=\w{4})/g包含字符.它似乎在这里工作.但是当我尝试在java中实现它时它不起作用.这是我的java代码中的一行:
String mask = accountNumber.replace("\\w(?=\\w{4})", "*");
Run Code Online (Sandbox Code Playgroud)
掩码最终与accountNumber相同.显然正则表达式不起作用.有什么想法吗?
我有一个看起来像这样的休息控制器:
@RequestMapping(
value = "/foo",
method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<JsonNode> getFOOs(@Valid Payload payload) {
/** some code **/
}
Run Code Online (Sandbox Code Playgroud)
这个Payload类看起来像这样:
@OneOrTheOther(first = "a", second = "b")
public final class Payload {
private final String userName;
private final String a;
private final String b;
@NotNull
private final String c;
@NotEmtpy{message="At least 1 item"}
private List<String> names = new ArrayList<String>();
}
Run Code Online (Sandbox Code Playgroud)
ArgumentResolver看起来像这样:
public class PayloadArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter methodParameter) {
return methodParameter.getParameterType().equals(Payload.class);
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试对包含int和每个元素中的字符串的向量进行排序.它是类型的向量,称为向量配方.得到上述错误,这是我的代码:
在我的Recipe.h文件中
struct Recipe {
public:
string get_cname() const
{
return chef_name;
}
private:
int recipe_id;
string chef_name;
Run Code Online (Sandbox Code Playgroud)
在我的Menu.cpp文件中
void Menu::show() const {
sort(recipes.begin(), recipes.end(), Sort_by_cname());
}
Run Code Online (Sandbox Code Playgroud)
在我的Menu.h文件中
#include <vector>
#include "Recipe.h"
using namespace std;
struct Sort_by_cname
{
bool operator()(const Recipe& a, const Recipe& b)
{
return a.get_cname() < b.get_cname();
}
};
class Menu {
public:
void show() const;
private
vector<Recipe> recipes;
};
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
这是代码:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string word="";
getline(cin,word);
word.erase(remove_if(word.begin(), word.end(), isspace), word.end());
word.erase(remove_if(word.begin(), word.end(), ispunct), word.end());
word.erase(remove_if(word.begin(), word.end(), isdigit), word.end());
}
Run Code Online (Sandbox Code Playgroud)
在VS 2010中编译时,它运行得非常好.用G ++编译它说:
hw4pr3.cpp: In function `int main()':
hw4pr3.cpp:20: error: no matching function for call to `remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
hw4pr3.cpp:21: error: no matching function for call to `remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown …Run Code Online (Sandbox Code Playgroud) 我正在创建一个注册页面,如果有人可以注册最多20个人.所以我有这些文本框:
First Name: <br/><input type="text" name="fname" id="fname" /> <br/>
Last Name: <br/><input type="text" name="lname" id="lname" /> <br/>
Email: <br/><input type="text" name="email" id="email"/> <br/>
Run Code Online (Sandbox Code Playgroud)
这是我使用DataTables的JQuery初始化的html表:
<div id="tables">
<table id="table" border="1">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
</table>
</div>
$('#reg_more').dataTable({
"bLengthChange": false,
"bInfo": false
});
Run Code Online (Sandbox Code Playgroud)
现在我想添加一个添加按钮,以便用户可以输入名字和姓氏,然后发送电子邮件并点击添加,它将被放入表格中.我该怎么做呢?
我有两个 C++ 程序:Program1 和 Program2。我想要做的是让 Program1 运行其算法来计算它需要的任何内容,然后将所有计算出的信息通过管道传输到 Program2 中,让它使用 Program1 的输出运行其算法。
如果我可以通过管道传递信息并关闭 Program1 而不必先等待 Program2 完成,那就太好了。它类似于python 中的subprocess.call()。
我有一个java可选对象,如果它存在,我只想得到它.这里显而易见的代码是:
JsonGenerator gen;
if(value.isPresent()) {
gen.writeObject(value.get());
}
Run Code Online (Sandbox Code Playgroud)
但我想知道我是否可以通过该ifPresent方法将其转换为1行.如果不存在,我根本不想写它.我试过这样的事情:
gen.writeObject(value.ifPresent(a -> a));
Run Code Online (Sandbox Code Playgroud)
但这显然不起作用.有什么办法可以做我想要的吗?我在网上研究的所有内容都只显示了ifPresent对谓词的方法调用的使用.
编辑1: 我尝试了Tunaki的解决方案但是我收到以下错误:
Error:(25, 46) java: incompatible thrown types java.io.IOException in method reference
Run Code Online (Sandbox Code Playgroud)
这是我的整个代码块:
public class FooSerializer extends JsonSerializer<Foo> {
@Override
public void serialize(Foo value,
JsonGenerator gen,
SerializerProvider serializers) throws IOException {
value.getFooA().ifPresent(gen::writeObject);
}
}
Run Code Online (Sandbox Code Playgroud)
我甚至尝试过:
public class FooSerializer extends JsonSerializer<Foo> {
@Override
public void serialize(Foo value,
JsonGenerator gen,
SerializerProvider serializers) throws IOException {
try {
value.getContactInfo().ifPresent(gen::writeObject);
} catch(IOException e) {
throw new UncheckedIOException(e);
} …Run Code Online (Sandbox Code Playgroud) 我有这样的类结构:
public class Foo {
private FooB foob;
public Optional<FooB> getFoob() {
return Optional.ofNullable(foob);
}
}
public class FooB {
private int valA;
public int getValA() {
return valA;
}
}
Run Code Online (Sandbox Code Playgroud)
我的目标是调用get方法fooB,然后检查它是否存在.如果它存在则返回valA属性,如果不存在则返回null.所以像这样:
Integer valA = foo.getFoob().ifPresent(getValA()).orElse(null);
Run Code Online (Sandbox Code Playgroud)
当然这不是正确的Java 8可选语法,但那是我的"伪代码".有没有办法在Java 8中用1行实现这一点?
我有一个 java/spring boot 应用程序,我想在其中构建一个 API 端点,该端点创建并返回一个可下载的 excel 文件。这是我的控制器端点:
@RestController
@RequestMapping("/Foo")
public class FooController {
private final FooService fooService;
@GetMapping("/export")
public ResponseEntity export() {
Resource responseFile = fooService.export();
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+responseFile.getFilename())
.contentType(MediaType.MULTIPART_FORM_DATA)
.body(responseFile);
}
}
Run Code Online (Sandbox Code Playgroud)
然后是服务类
public class FooService {
public Resource export() throws IOException {
StringBuilder filename = new StringBuilder("Foo Export").append(" - ")
.append("Test 1.xlsx");
return export(filename);
}
private ByteArrayResource export(String filename) throws IOException {
byte[] bytes = new byte[1024];
try (Workbook workbook = generateExcel()) {
FileOutputStream fos …Run Code Online (Sandbox Code Playgroud) java ×5
c++ ×3
html ×2
java-8 ×2
optional ×2
spring ×2
string ×2
apache-poi ×1
class ×1
consumer ×1
css ×1
datatables ×1
excel ×1
g++ ×1
hibernate ×1
html-table ×1
jquery ×1
masking ×1
navbar ×1
pipe ×1
regex ×1
remove-if ×1
rest ×1
row ×1
sorting ×1
spring-boot ×1
subprocess ×1
validation ×1
vector ×1