The thymeleaf template dynamically calls the service and dynamically passes parameters
front end
console.log([[${
patientInfo}]]) // 调用此页面时,后端传递的参数 patientInfo
var dept = [[${
@dict.getBySql('select t.target_value as dict_value, t.target_name as dict_label from hos_dict_compare t where hos_dict_type_code = ''01'' and t.hos_value = ''__${patientInfo.rykb}__''')}]];
console.log(dept);
illustrate:
Splicing the data acquired in the background '__${}__', both before and after are two underscores
1. When adding single quotes to the background, it is a string2. Without single quotation marks, the number __${}__ is passed to the background
service
@Service("dict")
public class DictService
{
@Autowired
private ISysDictDataService dictDataService;
/**
* 根据表名查询自定义字典数据信息
*
* @param sql sql语句
* @return 参数键值
*/
public List<SysDictData> getBySql(String sql)
{
return dictDataService.selectCustomDictDataBySql(sql);
}
}
controller
@RequestMapping(value = "/jumpToUpdateZkInfo/{id}",method = RequestMethod.GET)
public String jumpToUpdateZkInfo(@PathVariable Long id,BasyAuditResult basyAuditResult,ModelMap mmap){
AuditInfo patientInfo = auditInfoService.selectAuditInfoById(id);
mmap.put("basyAuditResult",basyAuditResult);
mmap.put("patientInfo",patientInfo);
return "test";
}