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 將值轉換為對象。謝謝大家!
添加回答
舉報