springboot 整合freemaker+mybatis

1 篇文章 0 订阅
0 篇文章 0 订阅
配置文件中的内容
#server
server.port=8888
########################################################
###                  \u6570\u636E\u6E90
########################################################
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/excel
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.initialSize=1
spring.datasource.minIdle=1
spring.datasource.maxActive=20

########################################################
###                      MYBATIS
########################################################
mybatis-plus.mapper-locations=classpath:mapper/**Mapper.xml
mybatis-plus.typeAliasesPackage=com/qmx/model
#\u4E3B\u952E\u7C7B\u578B  0:"\u6570\u636E\u5E93ID\u81EA\u589E", 1:"\u7528\u6237\u8F93\u5165ID",2:"\u5168\u5C40\u552F\u4E00ID (\u6570\u5B57\u7C7B\u578B\u552F\u4E00ID)", 3:"\u5168\u5C40\u552F\u4E00ID UUID";
mybatis-plus.global-config.id-type=2
#\u5B57\u6BB5\u7B56\u7565 0:"\u5FFD\u7565\u5224\u65AD",1:"\u975E NULL \u5224\u65AD"),2:"\u975E\u7A7A\u5224\u65AD"
mybatis-plus.global-config.field-strategy=2
#\u9A7C\u5CF0\u4E0B\u5212\u7EBF\u8F6C\u6362
mybatis-plus.global-config.db-column-underline=true
#\u5237\u65B0mapper \u8C03\u8BD5\u795E\u5668
mybatis-plus.global-config.refresh-mapper=true

########################################################
###                      FREEMARKER
########################################################
spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.freemarker-variables.base=#{servletContext.contextPath}
 以下是一基于springboot搭建的freemaker+mybatis 使用的是阿里的数据连接池,放到pom文件里面下载依赖即可使用
<!--spring-boot start-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<!--spring-boot End-->

<!-- freemarker -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!--freemarker End-->

<!-- mybatis-plus begin -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatisplus-spring-boot-starter</artifactId>
    <version>${mybatisplus-spring-boot-starter.version}</version>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus</artifactId>
    <version>${mybatisplus.version}</version>
</dependency>
<!-- mybatis-plus end -->

<!--alibaba-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.29</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>${fastjson.version}</version>
</dependency>
<!--alibaba End-->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
然后一个添加一个启动类即可



                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot + Freemarker 会自动跳转到 login 页的原因可能是因为你的应用程序中使用了 Spring Security,而 Spring Security 会默认开启登录验证功能。 如果你想要禁用 Spring Security 的登录验证功能,可以在 application.properties 或 application.yml 文件中添加以下配置: ``` spring.security.enabled=false ``` 如果你想要保留 Spring Security 的登录验证功能,可以在你的应用程序中添加一个自定义的登录页面,并将 Spring Security 的登录页面指向你的自定义登录页面。你可以按照以下步骤进行操作: 1. 创建一个自定义的登录页面。比如,你可以将登录页面的文件名设置为 "custom-login.html",并将其放置在 "/templates/" 目录下。 ``` <!DOCTYPE html> <html> <head> <title>Login Page</title> </head> <body> <h2>Login Page</h2> <form action="/login" method="POST"> <label for="username">Username:</label> <input type="text" id="username" name="username"><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Submit"> </form> </body> </html> ``` 2. 创建一个 Spring Security 的配置类,并在配置类中将登录页面指向你的自定义登录页面。 ``` @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/custom-login.html") .permitAll(); } } ``` 这样,当用户访问需要登录验证的页面时,Spring Security 就会自动跳转到你的自定义登录页面。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值