spring-mvc

Uploading files on to server using spring mvc

て烟熏妆下的殇ゞ 提交于 2021-02-11 14:09:56
问题 I am trying to upload list of files to the server using spring MVC. But i am able to store on to the c drive,but i don't know how to upload onto server.Please help me. 回答1: create a folder inside the Tomcat 9 (server) directory as follows .../Apache Software Foundation/Tomcat 9/FileUpload then, you can access the above directory (FileUpload) in java File fileUpload = new File(System.getProperty("catalina.base"), "FileUpload"); but, if you use the eclipse ide, in the development time you

Spring Security get CSRF token

大城市里の小女人 提交于 2021-02-11 13:46:30
问题 I am using Spring Security 4. Everything works fine until I decided to turn on CSRF to keep website security. But I am getting confused after reading lots of relevant documents. Here is the question: I have back-end services with Spring MVC and Spring Security running on Computer A , on Computer B I have all the front-end HTML. New I want to login in from webpages in Computer B , it always says Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'. I

NUnit 5 Spring MVC test NoSuchBeanDefinitionException for Autowired dependency in submodule

不打扰是莪最后的温柔 提交于 2021-02-11 13:26:53
问题 I have a project with two submodules; one is the data access layer the other is the API service. The data access module uses JOOQ and an autowired DSLContext in a service class. Also, I'm using JUnit 5, and Spring Boot 2.2.4. The QueryService class in the data access module has a member like @Autowired private DSLContext dsl ; The test class is set up like this: @SpringBootTest public class MyServiceTests { @Autowired QueryService service; @Autowired private DSLContext dsl; @Test public void

Spring boot JPA many to many with extra column insert and update issue

大城市里の小女人 提交于 2021-02-11 13:00:30
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

Spring boot JPA many to many with extra column insert and update issue

耗尽温柔 提交于 2021-02-11 13:00:29
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

What is the equivalent of die() in Spring?

二次信任 提交于 2021-02-11 13:00:17
问题 In PHP there is the die("some message"); to write output and stop the execution of the script. So is there an equivalent in Spring mvc ( in Controller and in the JSP ) ? 回答1: There is no reason to have something like die() in Java/JSPs. JSPs should be used as a pure view technology. It should just generate HTML. Not try to access a database, read files or whatnot. That is the job of a controller, written in Java Use System.exit(0); to exit the java code. Keep a note this will stop the JVM

Spring boot JPA many to many with extra column insert and update issue

吃可爱长大的小学妹 提交于 2021-02-11 12:59:24
问题 Here is my initial question. Spring Data JPA Many to Many with extra column User and Roles Now I have the right tables created, but can't make it work for the update. Here is the code: User.java @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; @OneToMany(mappedBy="user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List<UserRole> roles; // getters and setters

Embedded MongoDb not picked up for Application test

a 夏天 提交于 2021-02-11 12:24:41
问题 Application test AuthServiceApplicationTests.class is trying to run against local MongoDb instance which was setup for development and running behind the process. I shutdown this instance, and expected that it will run against embedded mongoDb with de.flapdoodle.embed.mongo . <!-- Integration Tests --> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> <version>2.2.0</version> <scope>test</scope> </dependency> <!--/ Integration Tests -->

How do I find base URL during Spring MVC startup?

青春壹個敷衍的年華 提交于 2021-02-11 12:07:30
问题 fellow programmers who lurks here at Stack Overflow. Today's question: How can I get the absolute baseUrl in Spring MVC Framework, from startup? I'm working with Spring MVC Framework for an application, and I'm in this situation: Let's say that I need to make objects of class Foo, inserted into a list. Every object contains an unique self-link (I'm using org.springframework.hateoas.Link for the real application, but that's beside the point). Example code: class Foo{ private int ID; private

“${#fields.hasErrors('*')}” always false - Redirect Problem

寵の児 提交于 2021-02-11 09:37:06
问题 My controller looks like this: @PostMapping("/event/{id}") public String save(@PathVariable("id") long id, @Valid Form form, BindingResult bindingResult ) { if (!bindingResult.hasErrors()) { //No errors //No return } return "redirect:/event/{id}"; } My @GetMapping is: @GetMapping("/event/{id}") public ModelAndView eventDetail(@PathVariable("id") long id) { ModelAndView model = new ModelAndView("event/details"); Event event = eventoRepository.findById(id).get(); model.addObject("event", evento