我对使用 git 跟踪的代码进行了一些更改。这些更改已上演(添加)。然后我使用git stash. 然后我使用git stash pop. 那时,更改不再上演。这是预期的行为吗?如果是这样,它是否在 git docs 中描述?
我在我的 React 应用程序中使用 ErrorBoundary,并希望在发生错误时重定向到主页 - 但我的重定向不起作用。相反,应用程序停留在同一页面上。
相比之下,添加按钮允许用户通过单击它来切换页面。
但我想在错误发生时自动将用户带到那里。
当然,我缺少一种简单的方法来做到这一点。
import React from 'react';
import { Redirect } from 'react-router-dom';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { error: null, errorInfo: null };
}
componentDidCatch(error, errorInfo) {
this.setState({
error: error,
errorInfo: errorInfo
})
console.log(error, errorInfo);
}
render() {
if (this.state.errorInfo) {
return (
<div>
{/* <Button href="/index.html">Go Home</Button> */}
<Redirect to="/index.html" />
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;
Run Code Online (Sandbox Code Playgroud)
我也尝试过返回一条路线,但没有成功:
render() {
if (this.state.errorInfo) { …Run Code Online (Sandbox Code Playgroud) 除了建立jdbc连接或使用内部使用jdbc的框架以外,还有其他任何方法可以连接到数据库。
这是关于第Spring4版(MVC +安全性).我已实现UserDetailsServiceImpl,其中内部loadUserByUsername方法用户被授予其权限.说它很简单:
public UserDetails loadUserByUsername(String username) {
...
Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ADMIN"));
return new org.springframework.security.core.userdetails.User(username, password, enabled, true, true, true, authorities);
...
}
Run Code Online (Sandbox Code Playgroud)
我有安全控制器,我在其中注释带有@Secured注释的方法:
@Secured("ADMIN")
@RequestMapping(value = "/users", method = RequestMethod.GET)
public String users(Model model ...) { ... }
Run Code Online (Sandbox Code Playgroud)
正如您在内部所见,loadUserByUsername我明确地ADMIN向用户授予角色.但是当我尝试访问时,/users我得到了Access is denied异常:
2016-04-19 10:25:16,899 DEBUG(http-nio-8080-exec-9)[org.springframework.security.web.access.ExceptionTranslationFilter] - 访问被拒绝(用户不是匿名的); 委托给AccessDeniedHandler org.springframework.security.access.AccessDeniedException:在org.springframework.security.access.vote.AffirmativeBased的org.springframework.security.access.vote.AbstractAccessDecisionManager.checkAllowIfAllAbstainDecisions(AbstractAccessDecisionManager.java:70)中拒绝访问.在org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:232)在org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java决定(AffirmativeBased.java:88): 64)在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)在org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)...
(没有@Secured注释一切正常).
那么,我在这里错过了什么?
在我的React项目中,webpack.config.js 引入了如下的提案类属性:
...
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
query: {
presets: ['@babel/react', '@babel/preset-env'],
plugins: ['@babel/proposal-class-properties']
}
},
}
...
Run Code Online (Sandbox Code Playgroud)
通过包含,@babel/proposal-class-properties我可以从我的 React 组件等中删除构造函数。
然而,该文件显示plugin-proposal-class-properties在.babelrc如下(并没有提及webpack.config.js在所有):
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
Run Code Online (Sandbox Code Playgroud)
而我的.babelrc根本不包含任何插件:
{
"presets": [
["@babel/env", {
"modules": false
},
"@babel/preset-env"]
]
}
Run Code Online (Sandbox Code Playgroud)
将插件(例如proposal-class-properties)包含在webpack.config.js与将它们放入相比之间是否有任何有效区别.babelrc?
我在我的 React 项目中使用react-bootstrap并按照他们记录的示例创建一个表单。如果我理解正确,我只需要导入form即可获得所有表单功能:
import Form from 'react-bootstrap/Form'
Run Code Online (Sandbox Code Playgroud)
具体来说,我正在关注这个非常简单的例子:
<Form>
<Form.Group as={Row} controlId="formPlaintextEmail">
<Form.Label column sm="2">
Email
</Form.Label>
<Col sm="10">
<Form.Control plaintext readOnly defaultValue="email@example.com" />
</Col>
</Form.Group>
<Form.Group as={Row} controlId="formPlaintextPassword">
<Form.Label column sm="2">
Password
</Form.Label>
<Col sm="10">
<Form.Control type="password" placeholder="Password" />
</Col>
</Form.Group>
</Form>
Run Code Online (Sandbox Code Playgroud)
但是,我在 Chrome DevTools 中收到以下错误:
MyComponent.jsx:430 Uncaught ReferenceError: Row is not defined
Run Code Online (Sandbox Code Playgroud)
我尝试导入行,但这并不能解决错误。任何想法缺少什么?
在我看来,要么他们记录的示例不完整或已损坏,要么我需要添加一些额外的导入以使用 react-bootstrap。
我有一些命令式 Java 条件代码,我想对其进行重构以使用 Streams。
具体来说,我有这张地图,我想根据特定的过滤条件过滤到一个列表中。
private Map<Integer,Thing> thingMap = new HashMap<Integer,Thing>();
// populate thingMap
Run Code Online (Sandbox Code Playgroud)
这是使用它的代码:
List<Thing> things = new ArrayList<Thing>();
for (Thing thing : thingMap.values()) {
if (thing.getCategory().equals(category)) {
if (location == null) {
things.add(thing);
} else if (thing.getLocation().equals(location)) {
things.add(thing);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我将其重构为以下内容。但是缺少的是我希望只有在类别过滤器通过时才检查位置。另外,我怀疑有更好的方法来做到这一点:
List<Thing> things = thingMap.entrySet()
.stream()
.filter(t -> t.getValue().getCategory().equals(category))
.filter(t ->
location == null ||
t.getValue().getLocation().equals(location)
)
.map(Map.Entry::getValue)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
使用 Streams 保留分层条件检查的惯用方法是什么?
我创建了一个使用 webpack-dev-server 的 React 项目,我的 package.json 是:
{
"name": "testproject",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --mode production",
"dev": "webpack --mode development",
"format": "prettier --write \"src/**/*.{js,jsx}\"",
"lint": "eslint **/*.{js,jsx} --quiet",
"start": "webpack-dev-server --mode development --open"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-react": "^7.14.5",
"babel-loader": "^8.2.2",
"css-loader": "^6.4.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.4.0",
"mini-css-extract-plugin": "^2.4.2",
"prettier": "^2.4.1",
"react": "^17.0.2",
"react-dom": …Run Code Online (Sandbox Code Playgroud) 我在我的代码中找不到错误。寻求帮助。为什么该方法不findById()返回具有此 id 的此类对象,但findAll()显示具有此 id 的此对象?
这是我的class User:
@Entity
@Table(name = "users")
public class User {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "login")
private String login;
@Column(name = "password")
private String password;
@JsonIgnore
@OneToOne(optional = false, mappedBy = "user")
private UserDetails userDetails;
}
Run Code Online (Sandbox Code Playgroud)
我的class UserDetails:
@Entity
@Table(name = "userdetails")
public class UserDetails {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private …Run Code Online (Sandbox Code Playgroud) 我有一个java.sql.Date对象,想将其转换为java.time.LocalDateTime对象。
为了进行比较,我可以使用以下方法进行类似的转换java.util.Date:
java.util.Date utilDate = new java.util.Date(sqlDate.getTime());
System.out.println("date with time: " + utilDate);
Run Code Online (Sandbox Code Playgroud)
这个答案对我不起作用,因为我java.sql.Date没有getTimestamp方法。
作为参考,这个问题涉及相反的转换。
似乎有两种方法可以从OSGi服务注册表获取配置管理服务.一个通过实例化BundleContext,然后从中获取ServiceReference,然后从中获取ConfigurationAdmin:
BundleContext bc = FrameworkUtil.getBundle(ManagedService.class).getBundleContext();
ServiceReference ca = bc.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(ca);
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用Blueprint并简单地创建对ConfigurationAdmin的引用,如下所示,然后在bean中引用它:
<reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
Run Code Online (Sandbox Code Playgroud)
这两种方法是否相同?或者前者的方法是否提供后者没有的任何东西?是否有任何Blueprint参考文档描述了它实例化ConfigurationAdmin(似乎找不到任何东西)的作用?