freemarker 中引用jsp标签 输出当前日期

<#global fundtradeTag=JspTaglibs["/WEB-INF/tld/fundTrade.tld"]>

<td>下单日期:</td>
            <td><@fundtradeTag.currDate/></td>

 

下面是文件

///WEB-INF/tld/fundTrade.tld

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
        "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
    <tlib-version>1.3</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>currDate</short-name>
      
    <tag>
        <name>currDate</name>
        <tag-class>com.howbuy.fundtrade.web.tag.CurrDateTag</tag-class>
        <body-content>JSP</body-content>
    </tag>
   
</taglib>

 

  /**
     * 标签类
     */

public class CurrDateTag extends BodyTagSupport{
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public int doStartTag() throws JspException {

       
        return Tag.EVAL_BODY_INCLUDE;
    }
    protected String renderDateElement() {
        return MfDate.today().toString(MfDate.defaultDatePattern);
    }
    public int doEndTag() throws JspException {
        try {
            JspWriter out = pageContext.getOut();
            String s = renderDateElement();
            out.print(s);
          
           
        } catch (Exception e) {
        }
        return (EVAL_PAGE);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Spring Boot 项目,您可以借助 Spring 的集成来更方便地使用 FreeMarkerJSP,同时使用 Spring 的 JDBC 模块来与数据库进行交互。以下是一个示例代码,演示如何将文件存储到 MySQL 数据库: 1. 添加依赖 在 pom.xml 文件添加以下依赖: ```xml <dependencies> <!-- Spring Boot Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- FreeMarker 模板引擎 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <!-- JDBC 模块 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!-- MySQL 驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- Tomcat JDBC 连接池 --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </dependency> </dependencies> ``` 2. 配置数据库连接 在 application.properties 文件添加数据库连接信息: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase spring.datasource.username=username spring.datasource.password=password ``` 3. 定义文件实体类 创建一个名为 FileEntity 的类,用于表示文件实体: ```java public class FileEntity { private Long id; private String name; private byte[] content; // 省略 getter 和 setter 方法 } ``` 4. 定义文件存储服务 创建一个名为 FileStorageService 的接口,定义文件存储服务的方法: ```java public interface FileStorageService { void save(FileEntity file); FileEntity getById(Long id); } ``` 在实现类,使用 Spring 的 JdbcTemplate 对象来执行 SQL 语句: ```java @Service public class FileStorageServiceImpl implements FileStorageService { @Autowired private JdbcTemplate jdbcTemplate; public void save(FileEntity file) { String sql = "INSERT INTO files (name, content) VALUES (?, ?)"; jdbcTemplate.update(sql, file.getName(), file.getContent()); } public FileEntity getById(Long id) { String sql = "SELECT * FROM files WHERE id = ?"; return jdbcTemplate.queryForObject(sql, new Object[]{id}, new RowMapper<FileEntity>() { public FileEntity mapRow(ResultSet rs, int rowNum) throws SQLException { FileEntity file = new FileEntity(); file.setId(rs.getLong("id")); file.setName(rs.getString("name")); file.setContent(rs.getBytes("content")); return file; } }); } } ``` 5. 定义控制器 创建一个名为 FileController 的控制器,在其注入 FileStorageService,并提供上传文件和下载文件的方法: ```java @Controller public class FileController { @Autowired private FileStorageService fileStorageService; @RequestMapping(value = "/upload", method = RequestMethod.POST) public String upload(@RequestParam("file") MultipartFile file) throws IOException { if (!file.isEmpty()) { FileEntity fileEntity = new FileEntity(); fileEntity.setName(file.getOriginalFilename()); fileEntity.setContent(file.getBytes()); fileStorageService.save(fileEntity); } return "redirect:/"; } @RequestMapping(value = "/download/{id}", method = RequestMethod.GET) public void download(@PathVariable("id") Long id, HttpServletResponse response) throws IOException { FileEntity fileEntity = fileStorageService.getById(id); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileEntity.getName() + "\""); response.getOutputStream().write(fileEntity.getContent()); } } ``` 6. 编写 FreeMarkerJSP 视图 在 FreeMarkerJSP 视图,您可以使用类似以下的语句来上传文件: ```html <form method="post" enctype="multipart/form-data" action="/upload"> <input type="file" name="file"/> <button type="submit">上传</button> </form> ``` 使用类似以下的语句来下载文件: ```html <a href="/download/${file.id}">${file.name}</a> ``` 在上述代码,${file.id} 和 ${file.name} 是从数据库检索文件得到的。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值