More Related Content Similar to Simple blog wall creation on Java Similar to Simple blog wall creation on Java (20) Simple blog wall creation on Java4. 1 run
mvn archetype:create
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-webapp
-DarchetypeVersion=1.0
-DgroupId=blog-wall
-DartifactId=blog-wall
-Dversion=1.0-SNAPSHOT
2 configure spring core and spring security
8. applicationContext-security.xml
• <authentication-manager>
• <authentication-provider>
• <jdbc-user-service data-source-ref="dataSource"
• users-by-username-query="
• select username,password, enabled
• from users where username=?"
• authorities-by-username-query="
• select u.username, ur.authority from users u, user_roles ur
• where u.user_id = ur.user_id and u.username =? "
• />
• <password-encoder ref="encoder"/>
• </authentication-provider>
• </authentication-manager>
9. blog-wall-servlet.xml
• <context:component-scan base-package="com.makstitoff.blogwall"/>
• <context:annotation-config/>
• <tx:annotation-driven transaction-manager="transactionManager"/>
• <bean id="entityManagerFactory"
• class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
• <property name="dataSource" ref="dataSource"/>
• <property name="jpaVendorAdapter">
• <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
• <property name="generateDdl" value="true"/>
• <property name="database" value="MYSQL"/>
• <property name="showSql" value="true"/>
• </bean>
• </property>
• <property name="persistenceUnitName" value="jpa.sample"/>
• </bean>
10. RegistrationController
• @Controller
• public class RegistrationController {
• @Autowired
• private UserService userService;
• @RequestMapping(value = "/register", method = RequestMethod.POST)
• public String createNewUser(final @RequestParam(value = "login",
required = true) String login, final @RequestParam(value = "password",
required = true) String password) {
• userService.createNewUser(login, password);
• return "redirect:/index.jsp";
• }
• }
11. PostController
• @Controller
• public class PostController {
• @Autowired
• private PostService postService;
• @RequestMapping(value = "/getAllPosts", method = RequestMethod.POST)
• public ModelAndView getAllPosts() {
• List<Post> posts = postService.getAll();
• return new ModelAndView("posts", "posts", posts);
• }
• @RequestMapping(value = "/post", method = RequestMethod.POST)
• public String post(@RequestParam(value = "text", required = true) String text) {
• if (text.length() > 1024) {
• text = text.substring(0, 1024);
• }
• postService.post(text);
• return "redirect:/index.jsp";
• }