Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. @Entity
  2. @Table(name = "menuitem")
  3. public class MenuItem {
  4.  
  5. @Id
  6. @GeneratedValue(strategy=GenerationType.IDENTITY )
  7. @Column(name = "id")
  8. private Integer id;
  9.  
  10. @Column(name = "title")
  11. private String title;
  12.  
  13. @Column(name = "eng_title")
  14. private String engTitle;
  15.  
  16. @Column(name = "price")
  17. private double price;
  18.  
  19. @Column(name = "description")
  20. private String description;
  21.  
  22. @Column(name = "consist_of")
  23. private String consistOf;
  24.  
  25. @Column(name = "volume_value")
  26. private double volumeValue;
  27.  
  28. @Column(name = "volume_title")
  29. private String volumeTitle;
  30.  
  31. @ManyToOne
  32. @JoinColumn(name = "category_id",insertable = false, updatable = false)
  33. private Category category;
  34.  
  35. @Column(name = "category_id")
  36. private int categoryId;
  37.  
  38. public MenuItem() {
  39.  
  40. }
  41.  
  42. public MenuItem(JSONObject jsonObject) {
  43. if (!jsonObject.isNull("id")) {
  44. this.id = jsonObject.getInt("id");
  45. }
  46.  
  47. if (!jsonObject.isNull("title")) {
  48. this.title = jsonObject.getString("title");
  49. }
  50.  
  51. if (!jsonObject.isNull("engTitle")) {
  52. this.engTitle = jsonObject.getString("engTitle");
  53. }
  54.  
  55. if (!jsonObject.isNull("price")) {
  56. this.price = jsonObject.getDouble("price");
  57. }
  58.  
  59. if (!jsonObject.isNull("description")) {
  60. this.description = jsonObject.getString("description");
  61. }
  62.  
  63. if (!jsonObject.isNull("consistOf")) {
  64. this.consistOf = jsonObject.getString("consistOf");
  65. }
  66.  
  67. if (!jsonObject.isNull("volumeValue")) {
  68. this.volumeValue = jsonObject.getDouble("volumeValue");
  69. }
  70.  
  71. if (!jsonObject.isNull("volumeTitle")) {
  72. this.volumeTitle = jsonObject.getString("volumeTitle");
  73. }
  74. }
  75.  
  76. public MenuItem(Integer id, String title, String engTitle, double price,
  77. String description, String consistOf, double volumeValue,
  78. String volumeTitle) {
  79. super();
  80. this.id = id;
  81. this.title = title;
  82. this.engTitle = engTitle;
  83. this.price = price;
  84. this.description = description;
  85. this.consistOf = consistOf;
  86. this.volumeValue = volumeValue;
  87. this.volumeTitle = volumeTitle;
  88. }
  89.  
  90.  
  91.  
  92. @Override
  93. public String toString() {
  94. return "MenuItem [id=" + id + ", title=" + title + ", engTitle="
  95. + engTitle + ", price=" + price + ", description="
  96. + description + ", consistOf=" + consistOf + ", volumeValue="
  97. + volumeValue + ", volumeTitle=" + volumeTitle + ", categoryId=" + categoryId + "]";
  98. }
  99.  
  100. public String getEngTitle() {
  101. return engTitle;
  102. }
  103.  
  104. public void setEngTitle(String engTitle) {
  105. this.engTitle = engTitle;
  106. }
  107.  
  108. public void setId(Integer id) {
  109. this.id = id;
  110. }
  111.  
  112. public Integer getId() {
  113. return id;
  114. }
  115.  
  116. public void setId(int id) {
  117. this.id = id;
  118. }
  119.  
  120. public String getTitle() {
  121. return title;
  122. }
  123.  
  124. public void setTitle(String title) {
  125. this.title = title;
  126. }
  127.  
  128. public double getPrice() {
  129. return price;
  130. }
  131.  
  132. public void setPrice(double price) {
  133. this.price = price;
  134. }
  135.  
  136. public String getDescription() {
  137. return description;
  138. }
  139.  
  140. public void setDescription(String description) {
  141. this.description = description;
  142. }
  143.  
  144. public String getConsistOf() {
  145. return consistOf;
  146. }
  147.  
  148. public void setConsistOf(String consistOf) {
  149. this.consistOf = consistOf;
  150. }
  151.  
  152. public double getVolumeValue() {
  153. return volumeValue;
  154. }
  155.  
  156. public void setVolumeValue(double volumeValue) {
  157. this.volumeValue = volumeValue;
  158. }
  159.  
  160. public String getVolumeTitle() {
  161. return volumeTitle;
  162. }
  163.  
  164. public void setVolumeTitle(String volumeTitle) {
  165. this.volumeTitle = volumeTitle;
  166. }
  167.  
  168. @JsonBackReference
  169. @JsonIgnore
  170. public Category getCategory() {
  171. return category;
  172. }
  173.  
  174. public void setCategory(Category category) {
  175. this.category = category;
  176. }
  177.  
  178. public void setCategoryId(int categoryId) {
  179. this.categoryId = categoryId;
  180. }
  181.  
  182. <beans:bean
  183. class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  184. <beans:property name="messageConverters">
  185. <beans:array>
  186. <beans:bean
  187. class="org.springframework.http.converter.StringHttpMessageConverter">
  188. <beans:property name="supportedMediaTypes" value="text/plain;charset=UTF-8" />
  189. </beans:bean>
  190. </beans:array>
  191. </beans:property>
  192. </beans:bean>
  193.  
  194. <!-- Resolves views selected for rendering by @Controllers to .jsp resources
  195. in the /WEB-INF/views directory -->
  196. <beans:bean
  197. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  198. <beans:property name="prefix" value="/WEB-INF/views/" />
  199. <beans:property name="suffix" value=".jsp" />
  200. </beans:bean>
  201.  
  202. <!-- Configure to plugin JSON as request and response in method handler -->
  203. <beans:bean
  204. class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  205. <beans:property name="messageConverters">
  206. <beans:list>
  207. <beans:ref bean="jsonMessageConverter" />
  208. </beans:list>
  209. </beans:property>
  210. </beans:bean>
  211.  
  212. <!-- Configure bean to convert JSON to POJO and vice versa -->
  213. <beans:bean id="jsonMessageConverter"
  214. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
  215. </beans:bean>
  216.  
  217. <mvc:interceptors>
  218. <beans:bean class="ru.tenet.cafe.interceptor.LoginInterceptor" />
  219. </mvc:interceptors>
  220.  
  221. <context:component-scan base-package="ru.tenet.cafe" />
  222.  
  223. <mvc:annotation-driven />
  224. <tx:annotation-driven transaction-manager="transactionManager" />
  225.  
  226. <beans:bean id="dataSourceMain" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  227. destroy-method="close">
  228. <beans:property name="driverClass" value="org.postgresql.Driver" />
  229. <beans:property name="jdbcUrl"
  230. value="jdbc:postgresql://192.168.101.158:5432/cafe" />
  231. <beans:property name="user" value="postgres" />
  232. <beans:property name="password" value="123" />
  233. <beans:property name="minPoolSize" value="5" />
  234. <beans:property name="maxPoolSize" value="8" />
  235. <beans:property name="preferredTestQuery" value="SELECT 1" />
  236. <beans:property name="acquireIncrement" value="1" />
  237. <beans:property name="idleConnectionTestPeriod" value="100" />
  238. <beans:property name="maxStatements" value="0" />
  239. <beans:property name="checkoutTimeout" value="60000" />
  240. </beans:bean>
  241.  
  242. <beans:bean id="sessionFactory"
  243. class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  244. <beans:property name="dataSource" ref="dataSourceMain" />
  245. <beans:property name="configLocation">
  246. <beans:value>/WEB-INF/db/hibernate.cfg.xml</beans:value>
  247. </beans:property>
  248. <beans:property name="hibernateProperties">
  249. <beans:props>
  250. <beans:prop key="hibernate.connection.characterEncoding">UTF-8</beans:prop>
  251. <beans:prop key="hibernate.connection.charSet">UTF-8</beans:prop>
  252. <beans:prop key="hibernate.connection.useUnicode">true</beans:prop>
  253. <beans:prop key="hibernate.show_sql">false</beans:prop>
  254. </beans:props>
  255. </beans:property>
  256.  
  257. </beans:bean>
  258.  
  259.  
  260.  
  261. <beans:bean id="transactionManager"
  262. class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  263. <beans:property name="sessionFactory" ref="sessionFactory" />
  264. </beans:bean>
  265.  
  266. @RequestMapping(value = "", method = RequestMethod.POST)
  267. public ResponseEntity<String> create(
  268. @RequestBody MenuItem menuItem) {
  269. menuService.create(menuItem);
  270. return new ResponseEntity<String>(HttpStatus.OK);
  271.  
  272. }
  273.  
  274. {
  275. "title":"Пепперони",
  276. "engTitle":"Pepperoni",
  277. "price":300,
  278. "description":"Сами лючщи пица слющи. Тольки щто привезли дарагой.",
  279. "consistOf":"E666, стальная стружка, вода (без ГМО)",
  280. "volumeValue":500,
  281. "volumeTitle":"г",
  282. "categoryId":38
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement