国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

幾個小總結

2019-11-11 05:02:10
字體:
來源:轉載
供稿:網(wǎng)友

從靜態(tài)map中取值添加進數(shù)組

public final static Map<String,Integer> WUHAN_AREAS = new LinkedHashMap<String,Integer>(); static { WUHAN_AREAS.put("北省", B_AREA_ID); WUHAN_AREAS.put("漢市", H_AREA_ID); WUHAN_AREAS.put("昌區(qū)", 04); WUHAN_AREAS.put("口區(qū)", 02); WUHAN_AREAS.put("陽區(qū)", 03); WUHAN_AREAS.put("山區(qū)", 05); WUHAN_AREAS.put("湖區(qū)", 06); WUHAN_AREAS.put("甸區(qū)", 07); WUHAN_AREAS.put("江區(qū)", 08); WUHAN_AREAS.put("黃區(qū)", 09); WUHAN_AREAS.put("新區(qū)", 10); WUHAN_AREAS.put("江區(qū)", 00); WUHAN_AREAS.put("漢區(qū)", 01); WUHAN_AREAS.put("南區(qū)", 11); WUHAN_AREAS.put("青區(qū)", 12); } //區(qū)的id數(shù)組 public final static Long[] HA_AREAS_ARY = new Long[HA_AREAS.size()]; static{ int i = 0; for(String key : HA_AREAS.keySet()){ HA_AREAS_ARY[i++] = Long.parseLong(HA_AREAS.get(key).toString()); } }

從項目編譯后的src下取文件到java

@Controller@RequestMapping("/opinion/risk")public class RiskController extends BaseController { @RequestMapping("loadInfo") public ModelAndView loadInfo(String beginDate,String endDate,Page page,int articleType,int sortType){ page.setPageSize(9); ModelAndView mav = new ModelAndView(); page = riskService.getRiskArticle(beginDate, endDate, sortType, articleType, page); List<NewsBean> newsList = page.getData(); StringUtil util = new StringUtil(); String path = RiskController.class.getResource("/").getPath(); String fileName=path + "config/opinionWord.txt"; List<String> wordlist =util.readFileByLines(fileName); for(NewsBean bean : newsList){ String title = bean.getTitle(); String fmtTitle =util.colorStrByOpinionWord(wordlist,title,"red"); bean.setTitle(fmtTitle); } mav.addObject("page", page); mav.setViewName(PATH_RISK + "articleInfo"); return mav; }}//StringUtil中的readFileByLines和colorStrByOpinionWord方法: /** * 讀取工程中的text文件 * @param filePath * @return */ public List<String> readFileByLines(String filePath){ List <String> li = new ArrayList<String>(); File file = new File(filePath); BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader( new FileInputStream(filePath),"UTF-8")); String tempString = null; while((tempString = br.readLine()) != null){ li.add(tempString); } br.close(); return li; } catch (FileNotFoundException e) { e.PRintStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br!= null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }/** * 給字符串中預警詞加高亮背景 * @param srcStr:源字符串 * @param color:高亮顏色 * @return */ public String colorStrByOpinionWord(List<String> wordlist, String srcStr, String color){ if(wordlist != null){ for(String keyword:wordlist){ if(keyword != null && !"".equals(keyword)){ color = (color == null || "".equals(color)) ? "red" : color;//默認紅色高亮 srcStr = srcStr.replaceAll(keyword, "<font color=/""+color+"/">" + keyword + "</font>"); } } return srcStr; } return null; }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 凯里市| 太仆寺旗| 苏尼特左旗| 田东县| 孙吴县| 阿拉善右旗| 龙川县| 沛县| 竹北市| 富川| 乌恰县| 政和县| 漳平市| 岐山县| 会理县| 谷城县| 鄂尔多斯市| 芦山县| 梁山县| 阿图什市| 兴宁市| 香港 | 南陵县| 泰州市| 盐城市| 巨野县| 山阴县| 都昌县| 澄迈县| 卫辉市| 呈贡县| 沾益县| 什邡市| 南城县| 安溪县| 清苑县| 枞阳县| 漳平市| 德清县| 潮安县| 金堂县|