我有一个冗长的形式,我已经破解了几个部分,并使用@ Html.EditorFor为每个部分工作得很好,但需要你的想法是否可以改进这种方法.
有段和每个段可以有多个活动,所以我有一个段的集合,此集合中的每个段包含一个活动集合.
public class Activity
{
public string ActivityId { get; set; }
public string ActivityDescription { get; set; }
public bool IsSelected { get; set; }
}
public class Segment
{
public string SegmentId { get; set; }
public string SegmentDescription { get; set; }
public List<Activity> Activitites { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这就是我希望我用作视图模型的ViewModel看起来如何,但由于@ Html.EditorFor不接受集合类型而无法使其工作.
public class UserPreferencesViewModel
{
//..... Other Properties
public List<Segment> Segments {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
这是ViewModel
@model UserPreferencesViewModel
@{
//... Other Properties
@Html.EditorFor(m => m.Segments) …Run Code Online (Sandbox Code Playgroud) 我很难让Spring Security OAuth2工作.我能够从/ oauth/token端点获取access_token,但是在标题"Authorization:Bearer $ TOKEN"中使用该令牌访问受保护资源时总是将我重定向到/ login.这是一个完整的REST API.
OAuth2Config
@Configuration
public class OAuth2Configuration {
private static final String SERVER_RESOURCE_ID = "oauth2-server";
private static InMemoryTokenStore tokenStore = new InMemoryTokenStore();
@Configuration
@EnableResourceServer
protected static class ResourceServer extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.tokenStore(tokenStore).resourceId(SERVER_RESOURCE_ID);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.requestMatchers().antMatchers("/admin**").and().authorizeRequests().antMatchers("/admin**").access("#oauth2.hasScope('read')");
}
}
@Configuration
@EnableAuthorizationServer
protected static class AuthConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager).tokenStore(tokenStore).approvalStoreDisabled(); …Run Code Online (Sandbox Code Playgroud) 的ViewModels
//MainViewModel
public class MainViewModel
{
public string UserID { get; set; }
public string ServiceType { get; set; }
public List<Service> Services {get; set;}
}
public class Service
{
public string ServiceID {get; set;}
public string ServiceName {get; set;
}
Run Code Online (Sandbox Code Playgroud)
这是视图
//Index.cshtml
@model ParentViewModel
@{
<div>
@Html.DropDownListFor(model => model.UserID, new{onchange="ddSelectionChanged(this)"})
<div id="services">
//This is filled with the ajax
</div>
</div>
}
Run Code Online (Sandbox Code Playgroud)
这是AJAX Call
<script>
function ddSelectionChanged(element){
$('#services').load('@(Url.Action("GetServices"))?serviceType =' element.value);
};
</script>
Run Code Online (Sandbox Code Playgroud)
这是控制器
//Controller
public class UserServicesController : Controller
{ …Run Code Online (Sandbox Code Playgroud) 我有一个在BasicAuthenticationFilter之前调用的自定义过滤器,Bean在SecurityConfig文件中自动装配.
.addFilterBefore(preAuthTenantContextInitializerFilter, BasicAuthenticationFilter.class)
Run Code Online (Sandbox Code Playgroud)
以下是过滤器的外观.
@Component
public class PreAuthTenantContextInitializerFilter extends OncePerRequestFilter {
@Autowired
private TenantService tenantService;
.....
.....
Run Code Online (Sandbox Code Playgroud)
我希望这个过滤器不会像Spring Security过滤器链的其余部分那样触发WebSecurityConfigurerAdapter #configure(WebSecurity web)web.ignoring()中包含的路径.
这是它的样子
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources",
"/configuration/security", "/swagger-ui.html",
"/webjars/**","/swagger-resources/configuration/ui",
"/swagge??r-ui.html", "/docs/**");
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了什么.
从过滤器类中删除@Component注释,它只会阻止过滤器在任何情况下调用,因为过滤器不再被选为bean并且永远不会进入过滤器链.
我在找什么
我希望在调用Spring安全链的其余部分时调用此过滤器,并在web.ignoring()中忽略其路径,就像其他Spring Security过滤器一样.谢谢.
我在接受采访时被问到,Select * from TableA如果需要花费大量时间来执行,我可以使用这些方法来优化查询.(TableA)可以是具有大量数据的任何表.面试官没有给我任何选择,如选择几列或使用"WHERE"条款而不是他希望我为主题查询提供解决方案.
我是.Net的初学者.最近我正在开展一个小型实践项目,我希望在VS .net 2008中使用数据集与SQL DB进行交互.请告诉我关于类型化数据集的几个读数.
asp.net-mvc ×2
spring ×2
spring-mvc ×2
asp.net ×1
asp.net-ajax ×1
c# ×1
editorfor ×1
razor ×1
spring-boot ×1
sql-server ×1
t-sql ×1