相对URL如何在Angular的HTTP请求中工作?例如,我看到有人这样做:
$http.post('/api/authenticate', { username: username, password: password });
Run Code Online (Sandbox Code Playgroud)
这里没有地址,只是一个相对的URL,如何在用户浏览器中运行javascript,找出要调用的地址?如果可能的话,请添加我可以阅读的材料的链接,以便更好地理解
我有一个Spring Boot应用程序,WebSecurityConfigurerAdapter配置如下 -
http.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.authorizeRequests()
.antMatchers("/user/*", "/habbit/*").authenticated()
.and()
.formLogin()
.loginProcessingUrl("/login")
.permitAll()
.usernameParameter("email")
.passwordParameter("pass")
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler())
.and()
.logout()
.logoutUrl("/logout")
.invalidateHttpSession(true);
Run Code Online (Sandbox Code Playgroud)
我可以添加类似我自己的控制器,在成功验证后,返回一个自定义对象,其中包含有关经过身份验证的用户的一些详细信息吗?
更新: 为了清晰起见,我使用角度应用程序作为客户端.目前,我需要从客户端向服务器发出2个请求:1.POST请求/登录URL进行身份验证.2. GET请求以检索经过身份验证的用户数据.
我的目标是让第一个请求返回给我用户信息,所以我不必提出2dn请求.目前,第一个请求仅对用户进行身份验证,在服务器上创建会话并发送回没有数据的"200 OK"状态响应.我希望它返回有关登录用户数据的成功响应.
回答:
正确的答案在评论中,所以我将在这里写:我需要从我的successHandler重定向到我的控制器,然后控制器返回当前登录的用户信息(在我的情况下控制器在url'/ user/me':
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException, IOException {
clearAuthenticationAttributes(request);
getRedirectStrategy().sendRedirect(request, response, "/user/me");
}
Run Code Online (Sandbox Code Playgroud) 我想在下面的代码中改进getCustomerFromDTO方法,我需要从接口{}创建一个结构,目前我需要将该接口编组为byte []然后将数组解组到我的结构中 - 必须有更好的方法.
我的用例是我通过rabbitmq发送结构并发送它们我使用这个通用DTO包装器,它有关于它们的其他域特定数据.当我从兔子mq收到DTO时,消息的一层被解组到我的DTO,然后我需要从该DTO获取我的结构.
type Customer struct {
Name string `json:"name"`
}
type UniversalDTO struct {
Data interface{} `json:"data"`
// more fields with important meta-data about the message...
}
func main() {
// create a customer, add it to DTO object and marshal it
customer := Customer{Name: "Ben"}
dtoToSend := UniversalDTO{customer}
byteData, _ := json.Marshal(dtoToSend)
// unmarshal it (usually after receiving bytes from somewhere)
receivedDTO := UniversalDTO{}
json.Unmarshal(byteData, &receivedDTO)
//Attempt to unmarshall our customer
receivedCustomer := getCustomerFromDTO(receivedDTO.Data)
fmt.Println(receivedCustomer)
} …Run Code Online (Sandbox Code Playgroud) 由于在一个EJB上使用了@Local和@Stateless,我在uni工作时拒绝了我的工作.它是一个帮助bean来验证/修复传递的对象.我认为用本地和无国籍来诠释我的ejb是完全合法的.有人可以向我解释为什么这会成为一个问题?
我正在使用 Apache freemarker 构建 PDF 文档报告。我遇到过这样的情况:页面的一半充满了文本,我需要在其下方添加一个表格。表格大小是动态的,有时它适合与文本在同一页面,有时不适合,如果不适合,我会在下一页上得到一些表格内容。我想测量表格是否适合在同一页上,如果不适合,我想将其打印在单独的页面上。有什么办法可以实现这一点吗?
就我而言,如果合适的话,将表格打印在同一页上很重要。
angularjs ×1
ejb-3.0 ×1
freemarker ×1
go ×1
java ×1
java-ee ×1
javascript ×1
rest ×1
spring ×1
spring-boot ×1
templating ×1