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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

幾個(gè)小總結(jié)

2019-11-11 05:39:40
字體:
供稿:網(wǎng)友

從靜態(tài)map中取值添加進(jìn)數(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()); } }

從項(xiàng)目編譯后的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; }/** * 給字符串中預(yù)警詞加高亮背景 * @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;//默認(rèn)紅色高亮 srcStr = srcStr.replaceAll(keyword, "<font color=/""+color+"/">" + keyword + "</font>"); } } return srcStr; } return null; }
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 湖州市| 上犹县| 广安市| 海南省| 余江县| 互助| 潞城市| 宜春市| 太白县| 喀喇| 麦盖提县| 襄汾县| 刚察县| 休宁县| 博湖县| 柳河县| 汽车| 墨脱县| 虹口区| 清水河县| 阳信县| 香港| 松原市| 江北区| 平南县| 泰来县| 克什克腾旗| 常熟市| 福泉市| 大城县| 石城县| 德钦县| 弋阳县| 连州市| 广元市| 修水县| 仁怀市| 汉川市| 张家口市| 二连浩特市| 中阳县|