当前位置: 首页 > news >正文

javaee springMVC数字类型转换之通过注解的方式

po

在属性上增加注解 @NumberFormat(pattern = “#,#.#”)

package com.test.pojo;import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;import java.util.Date;public class Users {private int uid;private String uname;private String pwd;//地址对象private Address address;@DateTimeFormat(pattern = "yyyy-MM-dd")private Date birthday;@NumberFormat(pattern = "#,#.#")private float money;public float getMoney() {return money;}public void setMoney(float money) {this.money = money;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public int getUid() {return uid;}public void setUid(int uid) {this.uid = uid;}public String getUname() {return uname;}public void setUname(String unamea) {this.uname = uname;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}public Address getAddress() {return address;}public void setAddress(Address address) {this.address = address;}@Overridepublic String toString() {return "Users{" +"uid=" + uid +", uname='" + uname + '\'' +", pwd='" + pwd + '\'' +", address=" + address +", birthday=" + birthday +", money=" + money +'}';}
}

spring配置文件

添加mvc:annotation-driven</mvc:annotation-driven>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!-- 1. 配置  需要扫描的控制层在哪个包  --><context:component-scan base-package="com.test.controller"></context:component-scan><!-- 2 配置 视图解析器 中的 前缀和后缀  --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 设置前缀  --><property name="prefix" value="/WEB-INF/"/><!-- 设置后缀 --><property name="suffix" value=".jsp"/></bean><!-- 开启注解驱动注册了两个数据转换的注解@NumberFormatannotation支持,@DateTimeFormatjson相关的。。--><mvc:annotation-driven></mvc:annotation-driven></beans>
http://www.lryc.cn/news/162669.html

相关文章:

  • SQL中CASE的用法
  • 自己的碎碎念集合
  • 暂定名「码道功成:Coder启示录」
  • Apache HTTPD (CVE-2017-15715)换行解析漏洞复现
  • Spring Boot集成JasperReport生成文档
  • 02-Tomcat打破双亲委派机制
  • 怎么理解flink的异步检查点机制
  • SpringMVC <url-pattern/>解读
  • 大学毕业设计的益处:培养实践能力、深入专业领域、展示自信与建立联系
  • ChatGPT:概述Vue.js中data函数初始化和created钩子函数调用的顺序和问题解决方法
  • SpringBoot【基础篇】
  • Vuex - state 状态(获取和使用共享数据)
  • tcp连接+套接字编程
  • OpenCV(三十四):轮廓外接最大、最小矩形和多边形拟合
  • Kafka3.0.0版本——消费者(offset的默认维护位置)
  • Wireshark技巧[监听串口包]
  • 安全运营中心即服务提供商评估
  • 算法通关村第十三关——幂运算问题解析
  • Python 之使用Numpy库来加载Numpy(.npy)文件并检查其内容
  • C#学习系列之UDP同端口收发问题
  • SpringMVC之文件上传下载以及jrebel的使用
  • 基于Fomantic UI Web构建 个人导航站点网站源码 网站技术导航源码
  • DRF02-请求响应与路由
  • http直接调用paddlepaddle实现文字转语音,语音转文字
  • 9. xaml ComboBox控件
  • 【后量子密码】CRYSTALS-KYBER 算法(二):密钥封装 KEM(附源码分析)
  • 什么是原⼦操作?在 JUC 中有哪些原⼦类?
  • 2022年12月 C/C++(八级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • Hadoop的HDFS的集群安装部署
  • uniapp 在 onLoad 事件中 this.$refs 娶不到的问题