数据库菜单栏的数据如何实现国际化

你看见了吗° 2019-12-17 10:26:18
从数据库取出数据,前端遍历获取展示菜单名字, 这些数据在国际化的时候,发现<spring:message code="" />,code写什么值,就是什么,根本不会进行转换,无法进行国际化

百度都说是只能在数据库加一个英文字段,然后根据当前语言动态读取中午或者英文数据.......

不知道有没有其他更便捷的方式?
...全文
586 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_46051159 2019-12-23
  • 打赏
  • 举报
回复
引用 楼主 <span style="color:#4788C7">来自底层程序猿的仰望</span>的回复:
引用 10 楼 weixin_46051159 的回复:
怎么做啊,啊啊啊啊
???
<br />数据库里取得菜单怎么做国际化啊
你看见了吗° 2019-12-23
  • 打赏
  • 举报
回复
引用 10 楼 weixin_46051159 的回复:
怎么做啊,啊啊啊啊
???
你看见了吗° 2019-12-18
  • 打赏
  • 举报
回复
引用 6 楼 maradona1984 的回复:
[quote=引用 5 楼 a229397620 的回复:]
[quote=引用 4 楼 maradona1984 的回复:]
断点下org.springframework.web.servlet.tags.MessageTag 也是可以的


{{each data as p_permission}}
{{if (p_permission.pid==null)}}
<li class="m" style="width:12%"><span class="icon-hamburg-bank" style="margin-right: 20px"></span>
<a href="#" value="{{p_permission.id }}" name="menu_a" class="mmm" style="width:100%">
<span class="t-btn-top t-btn-icon-top"><span class="t-btn-text" style="color:#cedae6;font-size:15px;"><strong>{{p_permission.name}}</strong></span><span class="t-btn-icon {{p_permission.icon }}"> </span></span>
</a>
</li>

{{/if}}

{{/each}}

这是页面的菜单遍历写法,菜单名称{{p_permission.name}}是这样获取,<spring:message code="" />code应该如何填写呢,我尝试了各个方式也不行[/quote]
...你这遍历是js模版吧...大兄弟
啥是前端执行啥是后端执行你都没整清楚吗?
用jstl遍历吧,spring的国际化都是后端渲染的,如果你真想前端渲染,那就换个前端的国际化组件,spring的自定义标签是支持el表达式传入参数的

[/quote]

惭愧,还真不懂,前端比较薄弱,一年写不了几个前端页面,
maradona1984 2019-12-18
  • 打赏
  • 举报
回复
引用 5 楼 a229397620 的回复:
[quote=引用 4 楼 maradona1984 的回复:] 断点下org.springframework.web.servlet.tags.MessageTag 也是可以的
{{each data as p_permission}}
						{{if (p_permission.pid==null)}}
							<li  class="m" style="width:12%"><span class="icon-hamburg-bank" style="margin-right: 20px"></span>
								<a href="#" value="{{p_permission.id }}" name="menu_a" class="mmm" style="width:100%">
									<span class="t-btn-top t-btn-icon-top"><span class="t-btn-text" style="color:#cedae6;font-size:15px;"><strong>{{p_permission.name}}</strong></span><span class="t-btn-icon {{p_permission.icon }}"> </span></span>
								</a>
							</li>
							
						{{/if}}
							
					{{/each}}
这是页面的菜单遍历写法,菜单名称{{p_permission.name}}是这样获取,<spring:message code="" />code应该如何填写呢,我尝试了各个方式也不行[/quote] ...你这遍历是js模版吧...大兄弟 啥是前端执行啥是后端执行你都没整清楚吗? 用jstl遍历吧,spring的国际化都是后端渲染的,如果你真想前端渲染,那就换个前端的国际化组件,spring的自定义标签是支持el表达式传入参数的
你看见了吗° 2019-12-17
  • 打赏
  • 举报
回复
引用 1 楼 土豆是我的最爱 的回复:
我们的项目这种国际化处理的数据都是写在xml文件中的,有英文,中文,香港(繁体)

我们是把code写在properties文件里面,数据库的菜单数据也是有配code,且数据库配的值就是code,但是国际化标签无法进行转换,
比如<spring:message code="${xxxx}" />,${xxxx}获取出来会是system,然后这个标签就会转换成系统管理,
但是这里直接是code值会直接等于${xxxx},然后提示你配置文件里没有${xxxx}这个code
  • 打赏
  • 举报
回复
我们的项目这种国际化处理的数据都是写在xml文件中的,有英文,中文,香港(繁体)
你看见了吗° 2019-12-17
  • 打赏
  • 举报
回复
引用 4 楼 maradona1984 的回复:
断点下org.springframework.web.servlet.tags.MessageTag 也是可以的


{{each data as p_permission}}
{{if (p_permission.pid==null)}}
<li class="m" style="width:12%"><span class="icon-hamburg-bank" style="margin-right: 20px"></span>
<a href="#" value="{{p_permission.id }}" name="menu_a" class="mmm" style="width:100%">
<span class="t-btn-top t-btn-icon-top"><span class="t-btn-text" style="color:#cedae6;font-size:15px;"><strong>{{p_permission.name}}</strong></span><span class="t-btn-icon {{p_permission.icon }}"> </span></span>
</a>
</li>

{{/if}}

{{/each}}

这是页面的菜单遍历写法,菜单名称{{p_permission.name}}是这样获取,<spring:message code="" />code应该如何填写呢,我尝试了各个方式也不行
maradona1984 2019-12-17
  • 打赏
  • 举报
回复
断点下org.springframework.web.servlet.tags.MessageTag 也是可以的
maradona1984 2019-12-17
  • 打赏
  • 举报
回复
springmvc的自定义标签的tld文件定义在spring-webmvc的META-INF里,我看了下message标签是支持读取JSP表达式的,按道理你的写法是没有问题的,我建议可以调试下,或者检查下你的springmvc版本的标签是否支持读取jsp表达式的 code定义的是<rtexprvalue>true</rtexprvalue>

	<tag>
		<description>
			Retrieves the message with the given code, or text if code isn't resolvable.
			The HTML escaping flag participates in a page-wide or application-wide setting
			(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
		</description>
		<name>message</name>
		<tag-class>org.springframework.web.servlet.tags.MessageTag</tag-class>
		<body-content>JSP</body-content>
		<attribute>
			<description>A MessageSourceResolvable argument (direct or through JSP EL).
				Fits nicely when used in conjunction with Spring's own validation error
				classes which all implement the MessageSourceResolvable interface. For
				example, this allows you to iterate over all of the errors in a form,
				passing each error (using a runtime expression) as the value of this
				'message' attribute, thus effecting the easy display of such error
				messages.</description>
			<name>message</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>The code (key) to use when looking up the message.
			If code is not provided, the text attribute will be used.</description>
			<name>code</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>Set optional message arguments for this tag, as a
			(comma-)delimited String (each String argument can contain JSP EL),
			an Object array (used as argument array), or a single Object (used
			as single argument). You can additionally use nested spring:argument
			tags.</description>
			<name>arguments</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>The separator character to be used for splitting the
			arguments string value; defaults to a 'comma' (',').</description>
			<name>argumentSeparator</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>Default text to output when a message for the given code
			could not be found. If both text and code are not set, the tag will
			output null.</description>
			<name>text</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>The string to use when binding the result to the page,
			request, session or application scope. If not specified, the result
			gets outputted to the writer (i.e. typically directly to the JSP).</description>
			<name>var</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>The scope to use when exporting the result to a variable.
			This attribute is only used when var is also set. Possible values are
			page, request, session and application.</description>
			<name>scope</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>Set HTML escaping for this tag, as boolean value.
			Overrides the default HTML escaping setting for the current page.</description>
			<name>htmlEscape</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<description>Set JavaScript escaping for this tag, as boolean value. Default is false.</description>
			<name>javaScriptEscape</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧