$sce 服务,设置服务器传来的数据为可渲染的html数据

服务器端:

service层:

@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private SolrTemplate solrTemplate;

    /**
     *
     * @param param
     * @return
     */
    @Override
    public Map search(Map param) {
        Map data = new HashMap<>();
        Query query = new SimpleQuery("*:*");
        String keywords = (String) param.get("keywords");
        if (keywords != null && StringUtils.isNotBlank(keywords)){
            HighlightOptions options = new HighlightOptions();
            options.addField("title");
            options.setSimplePrefix("");
            options.setSimplePostfix("");
            query = new SimpleHighlightQuery().setHighlightOptions(options);
            Criteria criteria = new Criteria("keywords").is(keywords);
            query.addCriteria(criteria);
            HighlightPage solrItems = solrTemplate.queryForHighlightPage((HighlightQuery) query, SolrItem.class);
            List> highlighted = solrItems.getHighlighted();
            for (HighlightEntry entry : highlighted) {
                SolrItem entity = entry.getEntity();
                if ( entry.getHighlights().size()> 0 && entry.getHighlights().get(0).getSnipplets().size()> 0){
                    String title = entry.getHighlights().get(0).getSnipplets().get(0);
                    entity.setTitle(title);
                }
            }
            List content = solrItems.getContent();
            data.put("rows",content);
            return data;
        }
        ScoredPage solrItems = solrTemplate.queryForPage(query, SolrItem.class);
        List content = solrItems.getContent();
        data.put("data",content);
        return data;
    }
}

controller层:

@RestController
@RequestMapping("/search")
public class SearchController {

    @Reference(timeout = 10000)
    private SearchService searchService;

    @PostMapping("/searchItem")
    public Map searchItem(@RequestBody Map param){
        try {
            return searchService.search(param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

js 代码:

html :





HelloWord




ng-bind-html 不能用在textarea标签

 

 

你可能感兴趣的:(angularjs)