我有一个基本的应用程序筛选器配置,如下所示:
@Configuration
public class ApplicationFilterConfig {
/**
* Check if user is logged in
*/
@Bean
public FilterRegistrationBean applicationFilterRegistration() {
// created a collections that need logins to be validated.
ArrayList<String> urlPatterns = new ArrayList<String>();
urlPatterns.add("/home");
urlPatterns.add("/about");
urlPatterns.add("/contact");
// ...
LoginFilter loginFilter = new LoginFilter();
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(loginFilter);
registration.setUrlPatterns(urlPatterns);
registration.setOrder(1);
return registration;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,urlPatterns即使使用星形注释(例如/employees/*),列表也会变得很长.我不仅仅使用的主要原因/*是因为我不想要求登录页面的登录验证.如果我这样做,它会创建一个无限循环的重定向.
FilterRegistrationBean该类是否允许您对除特定模式之外的所有URL模式应用过滤器?
我可以将除登录页面之外的所有内容放在一个目录中并设置我的URL模式,/subdirectory/*但这会为我的webapp中的每个文件添加不必要的深度.
这是我的基本 DAO 实现类:
@Repository
public class MeetingDaoImpl implements MeetingDao {
@Autowired
JdbcTemplate jdbcTemplate;
public boolean insertNewMeeting(String initials, String meetingId, int numYears) {
int numRowsAffected = jdbcTemplate.update(SQLConstants.INSERT_NEW_MEETING,
new Object[] {initials.toLowerCase(), meetingId, numYears});
return numRowsAffected > 0;
}
}
Run Code Online (Sandbox Code Playgroud)
该jdbcTemplate自动读取spring.datasource从我的属性application.properties文件,这是伟大的,但它包含了我的DB密码这是我不想犯。相反,我想从本地server.properties文件中读取它,而不是从 Java 类中轻松读取。
有没有办法jdbcTemplate用Java配置?我见过多个使用 bean 和 XML 的示例,但没有使用 Java。
我最近将 Spring Boot 应用程序从 1.5.10 升级到 2.0.3,现在面临这个问题:当我添加logging.level.root=DEBUG到我的时application.properties,出现以下异常:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "background-preinit" java.lang.StackOverflowError
at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
at java.util.logging.Logger.log(Logger.java:738)
at java.util.logging.Logger.doLog(Logger.java:765)
at java.util.logging.Logger.logp(Logger.java:931)
at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)
at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:103)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1154)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
at java.util.logging.Logger.log(Logger.java:738)
at java.util.logging.Logger.doLog(Logger.java:765)
at java.util.logging.Logger.logp(Logger.java:931)
at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)
at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:103)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1154)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
...
Run Code Online (Sandbox Code Playgroud)
这只是一小部分,因为这组堆栈跟踪重复了 100 多次,导致StackOverflowError.
我尝试过的调试步骤:
我有一个简单<div contenteditable>的<span>内部。<div>I want to be editable里面的文本,但<span>我不希望用户能够编辑。
样本:
#editable {
background-color: #ccc;
padding: 5px;
width: 400px;
text-align: center;
}
span {
background-color: green;
color: white;
padding: 2px;
}Run Code Online (Sandbox Code Playgroud)
<div id="editable" contenteditable>
Sample text including a <span>FANCY TAG</span> in the middle.
</div>Run Code Online (Sandbox Code Playgroud)
所需的最终结果是一个框,用户可以在其中输入他们想要的内容,但具有不可编辑的内嵌样式标签。由于您不能<span>在<input type="text">或<textarea>块内放置标签,因此我只能使用<div contenteditable>.
如何让所有的中的文本<div>编辑,除了在<span>?
我的页脚有一个简单的部分,如下所示:
<footer class="footer">
<nav>
<ul>
<li><%= link_to "Download History", report_histories_path(format: "csv") %>
<li><%= link_to "Help", help_path %></li>
<li><%= link_to "About", about_path %></li>
</ul>
</nav>
</footer>
Run Code Online (Sandbox Code Playgroud)
reports_controller第一个链接允许用户下载一些用于以 CSV 形式生成报告的数据,但我只希望在用于呈现部分内容时显示此链接。
我尝试过使用
<% if params[:reports] %>
<li><%= link_to "Download History", report_histories_path(format: "csv") %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
也
<% if current_page?(url_for(:controller => 'reports')) %>
<li><%= link_to "Download History", report_histories_path(format: "csv") %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但都不显示链接。
我<li>在<ul>带有display: inline-block.
但是,SVG每个里面的和 文本<li>并不垂直排列。我试过使用,vertically-align: middle因为它们是inline-block元素,但没有用。
理想情况下,两个元素的中间对齐,但对齐顶部或底部也可以。
svg {
height: 20px;
width: 20px;
display: inline-block;
background: green;
}
span {
background: blue;
}
#retweet-icon, #favorite-icon {
display: inline-block;
}
li.tweet-action {
height: 22px;
margin-left: 14px;
display: inline-block;
vertical-align: middle;
}
li.tweet-action:first-of-type {
margin-left: 0px;
}
ul#tweet-actions {
display: inline-block;
list-style-type: none;
float: left;
padding: 0px;
vertical-align: middle;
}Run Code Online (Sandbox Code Playgroud)
<ul id="tweet-actions">
<li class="tweet-action">
<div id="favorite-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 …Run Code Online (Sandbox Code Playgroud)是否可以像使用测试和 gemfile 一样在我的 seed.rb 代码中运行一两个块?
例如,如果我的seeds.rb 文件中有以下代码,我可以只为Employee模型播种吗?
20.times do
Employee.create!(name: "Bob",
email: Faker::Internet.email)
end
20.times do
User.create!(name: "Hank",
password: "foobar")
end
Run Code Online (Sandbox Code Playgroud)
如果这是我的整个 seed.rb 文件,rake db:seed当我只想添加更多员工时,运行会创建 20 个额外的用户。