Cześć,
jako że zawsze tutaj znajdowałem osoby chcące pomóc, proszę o nią jeszcze raz. Mam problem z kodem - wali błędami i nie mogę zlokalizować przyczyny. Aplikacja mi się nie odpala. W załączeniu screen.
oto mój kod:
import BugTrackerr.enums.AuthorityName;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.*;
@Entity
@NoArgsConstructor
@Getter
public class Authority { *//podkresla mi authority*
@Id
@GeneratedValue
Long id;
@Column(nullable = false, unique = true)
@Enumerated(EnumType.STRING)
AuthorityName name;
public Authority(AuthorityName nam) {
this.name = name;
}
}
klasa AuthorityRepository
package BugTrackerr.auth;
import BugTrackerr.enums.AuthorityName;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.Optional;
public interface AuthorityRepository extends JpaRepository<Authority, Long> {
Authority findByName(AuthorityName name);
@Query("select a from Person p join p.authorities a where p.username = :username order by a.authority") *//podkreśla a.authority*
Iterable<Authority> findAllByPersonUsername(String username);
Optional<Authority> findByAuthority(String authority);
}
klasa Person
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;
@Entity
@NoArgsConstructor
@Getter
@Setter
public class Person { *//podkreśla mi Person*
@Id
@GeneratedValue
Long id;
@Column(nullable = false, unique = true)
String username;
@Column(nullable = false)
String password;
@Column(nullable = false)
String name;
@Column(nullable = false)
@ColumnDefault(value = "true")
Boolean enabled = true;
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "person_authorities", *//podkreśla person_authorities*
joinColumns = @JoinColumn(name = "person_id"), *//podkreśla person_id*
inverseJoinColumns = @JoinColumn(name = "authority_id")) *//podkreśla authority_id*
Set<Authority> authorities;
public Person(String username, String password, String name) {
this.username = username;
this.password = password;
this.name = name;
}
public void setPassword(String hashedPassword) {
}
public void setAuthorities(HashSet<Authority> authorities) {
}
}
Person Controller
package BugTrackerr.auth;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.validation.Valid;
@Controller
@RequestMapping("/users")
public class PersonController {
private final PersonService personService;
public PersonController(PersonService personService) {
this.personService = personService;
}
@GetMapping("/")
@Secured("ROLE_USERS_TAB")
ModelAndView index() {
ModelAndView modelAndView = new ModelAndView("users/index");
modelAndView.addObject("people", personService.findAllUsers());
return modelAndView;
}
@GetMapping("/create")
@Secured("ROLE_CREATE_USER")
ModelAndView create() {
ModelAndView modelAndView = new ModelAndView("users/create");
modelAndView.addAllObjects("person", new Person()); *podkreśla ())*
return modelAndView;
}
@PostMapping(value = "/save")
@Secured("ROLE_CREATE_USER")
ModelAndView createNewUser(@Valid @ModelAttribute Person person) {
ModelAndView modelAndView = new ModelAndView();
personService.savePerson(person);
modelAndView.setViewName("redirect:/people/");
return modelAndView;
}
}
Pozdrawiam :)
- 179402341_164006472296651_893162896475733242_n.png (155 KB) - ściągnięć: 18