3、如何配置http的属性?

创建自定义 security 配置类 WebSecurityConfig 如下:

//@EnableWebSecurity(debug = false)
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
    }
}

super.configure(http);中使用的默认配置为父类中的

protected void configure(HttpSecurity http) throws Exception {
    this.logger.debug("Using default configure(HttpSecurity). "
                      + "If subclassed this will potentially override subclass configure(HttpSecurity).");
    http.authorizeRequests((requests) -> requests.anyRequest().authenticated());//所有请求需要进行认证
    http.formLogin();//开启form表单登录
    http.httpBasic();//开启 Basic Auth 登录
}

那我们可以覆盖父类的配置,比如这样

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests((requests) -> requests.anyRequest().authenticated());
        http.formLogin().usernameParameter("loginName").passwordParameter("passwd");//将登录用户名和密码改成我么需要的
        http.httpBasic();
        http.csrf().disable();//关闭csrf认证
    }
}

使用post登录
在这里插入图片描述

配置 'sqlSessionFactory' 或者 'sqlSessionTemplate' 属性,你需要进行以下步骤: 1. 首先,确保你已经引入了MyBatis框架的依赖包,并在项目的配置文件中配置了MyBatis的相关信息。 2. 配置 'sqlSessionFactory' 属性: - 在配置文件中添加一个数据源(DataSource)的配置,指定数据库连接信息。 - 配置 MyBatis 的 SqlSessionFactoryBean,设置数据源和其他相关属性。 - 配置 MyBatis 的 MapperLocations,指定 Mapper 文件的位置。 - 配置 MyBatis 的 TypeAliasesPackage,指定实体类的包路径。 以下是一个示例配置文件的代码片段: ```xml <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!-- 数据库连接信息 --> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/mydatabase" /> <property name="username" value="root" /> <property name="password" value="password" /> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 设置数据源 --> <property name="dataSource" ref="dataSource" /> <!-- 设置 Mapper 文件的位置 --> <property name="mapperLocations" value="classpath:mapper/*.xml" /> <!-- 设置实体类的包路径 --> <property name="typeAliasesPackage" value="com.example.model" /> </bean> ``` 3. 配置 'sqlSessionTemplate' 属性: - 在配置文件中添加一个 'sqlSessionFactory' 的引用。 - 配置 MyBatis 的 SqlSessionTemplateBean,设置 'sqlSessionFactory' 属性。 以下是一个示例配置文件的代码片段: ```xml <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <!-- 设置 'sqlSessionFactory' 的引用 --> <constructor-arg ref="sqlSessionFactory" /> </bean> ``` 这样,你就成功配置了 'sqlSessionFactory' 或者 'sqlSessionTemplate' 属性
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值