Spring/SpringBoot中获取list参数,并且还有其他参数如String,前后端如何解决

controller

@RequestMapping("/queryByBrandAndLocation")
public PagesUtil<Furniture> queryByBrandAndLocation(@RequestParam(value = "furnName", required = false) String furnName,
                                                        @RequestParam(value = "brands", required = false) List<String> brands,

页面

 //jquery获取复选框值
        var brands =[];//定义一个数组
        $('input[name="brand"]:checked').each(function(){//遍历每一个名字为interest的复选框,其中选中的执行函数
            brands.push($(this).val());//将选中的值添加到数组chk_value中
        });

        var locations =[];//定义一个数组
        $('input[name="location"]:checked').each(function(){//遍历每一个名字为interest的复选框,其中选中的执行函数
            locations.push($(this).val());//将选中的值添加到数组chk_value中
        });

 $("#zhineng").click(function () {
            $.ajax({
                url:"/queryByBrandAndLocation",
                type:"get",
                data:{brands:brands,locations:locations,"furnName":furnName,"typeId":typeId,"pageIndex":pageIndex},
                dataType:"json",
                success:function (data) {
 						。。。
                }
            });
        });
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SpringBoot和Vue前后端分离的解决方案是非常常见的,而SpringSecurity则是SpringBoot处理权限问题的最佳解决方案之一。下面介绍一下如何使用SpringSecurity完美处理权限问题。 1. 引入SpringSecurity依赖 在pom.xml引入SpringSecurity依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> ``` 2. 配置SpringSecurity 在SpringBoot应用,可以通过继承WebSecurityConfigurerAdapter类来配置SpringSecurity,代码如下: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private CustomUserService customUserService; @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/", "/index").permitAll() .antMatchers("/admin/**").hasRole("ADMIN") .anyRequest().authenticated() .and() .formLogin().loginPage("/login").defaultSuccessUrl("/home").permitAll() .and() .logout().logoutUrl("/logout").logoutSuccessUrl("/login").permitAll(); } @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(customUserService).passwordEncoder(new BCryptPasswordEncoder()); } @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/static/**"); } } ``` 3. 自定义用户认证 在上面的代码,我们使用了自定义的用户认证服务CustomUserService。CustomUserService实现了UserDetailsService接口,代码如下: ```java @Service public class CustomUserService implements UserDetailsService { @Autowired private UserRepository userRepository; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User user = userRepository.findByUsername(username); if (user == null) { throw new UsernameNotFoundException("用户名不存在!"); } List<GrantedAuthority> authorities = new ArrayList<>(); for (Role role : user.getRoles()) { authorities.add(new SimpleGrantedAuthority(role.getName())); } return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), authorities); } } ``` 在上面的代码,我们使用了自定义的UserRepository来获取用户信息,然后将用户的角色转换成GrantedAuthority对象,返回给SpringSecurity。 4. 在Vue处理权限问题 在Vue,我们可以通过Vue Router的导航守卫来处理权限问题。代码如下: ```javascript import router from './router' import store from './store' router.beforeEach((to, from, next) => { if (to.meta.requireAuth) { // 判断该路由是否需要登录权限 if (store.state.token) { // 获取当前的token是否存在 next() } else { next({ path: '/login', query: {redirect: to.fullPath} // 将跳转的路由path作为参数,登录成功后跳转到该路由 }) } } else { next() } }) ``` 在上面的代码,我们通过store来获取当前用户的token,如果token存在则允许访问,否则跳转到登录页面。 以上就是使用SpringSecurity处理权限问题的完整解决方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值