日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

资源读取配置

發(fā)布時間:2025/7/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 资源读取配置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

第一步:建立資源文件

1.Messages.properties

vo.edit.msg = {0} \u4fe1\u606f\u7f16\u8bd1\u5b8c\u6210\uff01

2.Pages.properties

emp.add.page=/pages/back/emp/emp_add.jsp

3.Validations.properties

emp.add.rules=empno:int|ename:string|sal:double|hiredate:date

第二步:配置applicationContext-mvc.xml

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"><property name="basenames"><array><value>Messages</value><value>Pages</value><value>Validations</value></array></property> </bean>

第三步:父類中定義讀取方法

package group.esperanto.action.util;import java.text.SimpleDateFormat; import java.util.Locale; import javax.annotation.Resource; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.context.MessageSource; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder;public class AbstractAction {@Resource //通過容器注入msgSourceprivate MessageSource msgSource;// 定義讀取資源文件內(nèi)容 msgKey指properties文件中的鍵,args指傳過來的參數(shù),替代properties中的占位符public String getValue(String msgKey,Object...args){return this.msgSource.getMessage(msgKey, args, Locale.getDefault());} }

第四步:控制器中讀取

package group.esperanto.action;import java.io.IOException; import java.util.Date; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.sound.midi.MidiDevice.Info; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import group.esperanto.action.util.AbstractAction;@Controller // 定義該Action的映射路徑 // 該路徑絕對不能重復(fù) @RequestMapping("/pages/emp/*") public class EmpAction extends AbstractAction { private Logger log = Logger.getLogger(EmpAction.class);@RequestMapping("info")public ModelAndView Info(){log.info(super.getValue("vo.edit.msg", "info "));log.info(super.getValue("emp.add.page"));log.info(super.getValue("emp.add.rules"));return null;}}

?

轉(zhuǎn)載于:https://my.oschina.net/u/3647851/blog/1507359

總結(jié)

以上是生活随笔為你收集整理的资源读取配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。