-
Notifications
You must be signed in to change notification settings - Fork 79
g596.kozlova.task4 #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
g596.kozlova.task4 #324
Conversation
|
А кроме калькулятора что-нибудь будет? Калькулятор не очень похож на тот, который требуется в задании Нужно разбирать строки с переменными и как-то хранить их результаты. Во-вторых, ты не можешь себе позволить разбирать строки с выражениями - как для переменных, так и для функций - каждый раз. Кроме переменных нужно хранить и разбор функций в том виде, в котором их значение можно максимально быстро посчитать. В стандартном подходе это выглядит как-нибудь так В-третьих, обрати внимание, что хочется уметь вычислять выражение функции, которая зависит от функции, вообще говоря: Если правильно реализовать хранение, это не будет слишком сложно |
| jdbcTemplate.update("INSERT INTO billing.variables VALUES (?, ?, ?, ?)", | ||
| new Object[]{userName, name, value, expression}); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще есть merge. C ним можно обновлять существующие значения и добавлять новые - не нужно будет удалять
| return jdbcTemplate.queryForObject( | ||
| "SELECT username, password, enabled FROM billing.users WHERE username = ?", | ||
| new Object[]{userName}, | ||
| new RowMapper<BillingUser>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Анонимные классы с единственным методом нынче заменяют на лямбда функции обычно. Получается компактнее и (по крайней мере, когда привыкнешь) читабельнее
| return false; | ||
| } catch (EmptyResultDataAccessException e) { | ||
| jdbcTemplate.update("INSERT INTO billing.users VALUES (?, ?, ?)", | ||
| new Object[]{userName, password, enabled}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут можно было не создавать массив, просто передать все аргументы:
jdbcTemplate.update("INSERT INTO billing.users VALUES (?, ?, ?)", userName, password, enabled);
| .csrf().disable() | ||
| .authorizeRequests() | ||
| .antMatchers("/eval/**").authenticated() | ||
| .antMatchers("/var/**").authenticated() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Судя по всему, "/variable/**" и "/function/**" должны быть
homework-g596-kozlova/pom.xml
Outdated
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-context</artifactId> | ||
| <version>4.1.6.RELEASE</version> | ||
| </dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лишняя зависимость. У меня из-за неё не собиралось
| import static java.lang.Character.isLetter; | ||
|
|
||
| @RestController | ||
| public class CalculatorController { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно весь контроллер пометить @RequestMapping(produces = "text/plain") и не писать во всех остальных методах
|
|
||
| public Function getFunction(String userName, String function) { | ||
| return jdbcTemplate.queryForObject( | ||
| "SELECT userName, name, arguments, expression FROM billing.functions WHERE userName = ? AND name = ?", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А где ты создаешь billing.functions?
| @RequestMapping(path = "/function/{functionName}", method = RequestMethod.PUT, consumes = "text/plain", | ||
| produces = "text/plain") | ||
| public void putFunction(Authentication authentication, @PathVariable String functionName, | ||
| @RequestParam(value = "arguments", defaultValue = "") Array arguments, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему Array? Оно реально работает? У меня не захотело
Only calculator