org.springframework.ui.Model addAttribute 数字被格式化

今天发现org.springframework.ui.Model addAttribute 方法放进去的数字超过三位数时被格式化,前端获取到的格式是这样的9,999,尝试使用parseInt转成数字,结果被转成9

解决方法:
在这里插入图片描述
提前将数字转成字符串即可,也能防止精度丢失的问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好的和spring集成.下面开始学习. 1.引入依赖 maven中直接引入 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 1 2 3 4 可以查看依赖关系,发现spring-boot-starter-thymeleaf下面已经包括了spring-boot-starter-web,所以可以把spring-boot-starter-web的依赖去掉. 2.配置视图解析器 spring-boot很多配置都有默认配置,比如默认页面映射路径为 classpath:/templates/*.html 同样静态文件路径为 classpath:/static/ 在application.properties中可以配置thymeleaf模板解析器属性.就像使用springMVC的JSP解析器配置一样 #thymeleaf start spring.thymeleaf.mode=HTML5 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html #开发时关闭缓存,不然没法看到实时页面 spring.thymeleaf.cache=false #thymeleaf end 1 2 3 4 5 6 7 具体可以配置的参数可以查看 org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties这个类,上面的配置实际上就是注入到该类中的属性值. 3.编写DEMO 1.控制器 @Controller public class HelloController { private Logger logger = LoggerFactory.getLogger(HelloController.class); /** * 测试hello * @return */ @RequestMapping(value = "/hello",method = RequestMethod.GET) public String hello(Model model) { model.addAttribute("name", "Dear"); return "hello"; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2.view(注释为IDEA生成的索引,便于IDEA补全) <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>hello</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <!--/*@thymesVar id="name" type="java.lang.String"*/--> <p th:text="'Hello!, ' + ${name} + '!'" >3333</p> </body> </html> 1 2 3 4 5 6 7 8 9 10 11 3.效果

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Abdulaziz02

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值