标签:src val ble end blog false pos nal crud
转载 https://github.com/springside/springside4/wiki/Tutorial
create table acct_user ( id bigint generated by default as identity, email varchar(255), login_name varchar(255) not null unique, name varchar(255), password varchar(255), primary key (id) ) ;
@Entity @Table(name = "acct_user") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class User extends IdEntity { private String loginName; private String password; private String name; private String email; //... getter and setter }
public interface UserDao extends PagingAndSortingRepository<User, Long> { User findByLoginName(String loginName); }
@Component @Transactional(readOnly = true) public class AccountManager { private UserDao userDao; public User getUser(Long id) { return userDao.findOne(id); } @Transactional(readOnly = false) public void saveUser(User entity) { userDao.save(entity); } }
@Controller @RequestMapping(value = "/account/user") public class UserController { private AccountManager accountManager; @RequestMapping(value = { "list", "" }) public String list(Model model) { List<User> users = accountManager.getAllUser(); model.addAttribute("users", users); return "account/userList"; } @RequestMapping(value = "create") public String createForm(Model model) { model.addAttribute("user", new User()); return "account/userForm"; } @RequestMapping(value = "save") public String save(User user, RedirectAttributes redirectAttributes) { accountManager.saveUser(user); redirectAttributes.addFlashAttribute("message", "Create user " + user.getLoginName() + " success"); return "redirect:/account/user/"; } }
@Controller @RequestMapping(value = "/account/user/") public class UserDetailController { private AccountManager accountManager; @RequestMapping(value = "update/{id}") public String updateForm(Model model) { return "account/userForm"; } @RequestMapping(value = "save/{id}") public String save(@ModelAttribute("user") User user, RedirectAttributes redirectAttributes) { accountManager.saveUser(user); redirectAttributes.addFlashAttribute("message", "Modify user " + user.getLoginName() + " success"); return "redirect:/account/user/"; } @ModelAttribute("user") public User getAccount(@PathVariable("id") Long id) { return accountManager.getUser(id); } }
标签:src val ble end blog false pos nal crud
原文地址:http://www.cnblogs.com/carr/p/7212596.html