2 回答
TA贡献1934条经验 获得超2个赞
我刚刚实现了 org.springframework.core.convert.converter.Converter;
@Component
public class RoleToUserProfileConverter implements Converter<Object, UserProfile>{
@Autowired
UserProfileService userProfileService;
public UserProfile convert(Object element) {
Integer id = Integer.parseInt((String)element);
return userProfileService.findById(id);
}
}
并稍微修改了这个表格
<select class="form-control input-sm" id="userProfiles" name="userProfiles" multiple="multiple" th:required="true">
<option th:each="role : ${allRoles}"
th:value="${role.id}"
th:text="${role.type}"
th:selected="${role.id == 1}"
>Role
</option>
</select>
所以现在,thymeleaf 将值转换为对象。谢谢大家!
添加回答
举报