Java开发之手把手教你搭建企业级工程SSM框架

这篇文章主要为大家介绍Java教程中搭建企业级工程SSM框架,手把手的过程操作,有需要的朋友可以借鉴参考下,希望能够有所帮助

关于Spring + Spring MVC + MyBatis的搭建

1.在IDEA界面中创建MavenWeb工程

选中下图maven-archetype-webapp

2.在pom.xml中添加如下相关依赖

   4.0.0org.examplessm1.0-SNAPSHOTwarssm Maven Webapphttp://www.example.com UTF-81.81.8  org.springframeworkspring-webmvc5.3.9 org.springframeworkspring-jdbc5.3.9 org.springframeworkspring-aop5.3.9 org.springframeworkspring-aspects5.3.9 org.mybatismybatis-spring2.0.6 org.mybatismybatis3.4.5 mysqlmysql-connector-java8.0.11 c3p0c3p00.9.1.2 org.projectlomboklombok1.18.20 jstljstl1.2 javax.servletjavax.servlet-api4.0.1 ssm  maven-clean-plugin3.1.0 maven-resources-plugin3.0.2 maven-compiler-plugin3.8.0 maven-surefire-plugin2.22.1 maven-war-plugin3.2.2 maven-install-plugin2.5.2 maven-deploy-plugin2.8.2  src/main/java **/*.xml

3.web.xml 配置 Spring MVC、Spring

设置字符编码过滤器、加载静态资源。

  Archetype Created Web Application contextConfigLocationclasspath:spring.xml org.springframework.web.context.ContextLoaderListener dispatcherorg.springframework.web.servlet.DispatcherServlet contextConfigLocationclasspath:springmvc.xml dispatcher/ characterorg.springframework.web.filter.CharacterEncodingFilter encodingutf-8 forceRequestEncodingtrue forceResponseEncodingtrue character/* default*.js default*.png-600 default*.css

4.分别在main目录下创建resource包

并创建spring,springmvc,mybatis.xml文件

5.在spring.xml中连接数据库

将user和password改成自己的数据库用户名和密码,并将3306/后面改成连接数据库的包名,紧接着配置SqlSessionFactory,扫描Mapper接口,事务管理等。

          

6.springmvc.xml中配置驱动和前后缀表达式

    

7.配置打印sql语句和指定实体类,让idea搜索需要的javaBean

     

8.创建与数据库相对应的实体类

9.Handler

 package com.south.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.south.service.UserService; @Controller @RequestMapping("/user") public class UserHandler { @Autowired private UserService userService; @GetMapping("/index") public ModelAndView index(){ ModelAndView modelAndView=new ModelAndView(); modelAndView.setViewName("index"); modelAndView.addObject("list",userService.findAll()); return modelAndView; } }

10.Service及其接口

 package com.south.service.impl; import com.south.entity.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.south.repository.UserRepository; import com.south.service.UserService; import java.util.List; @Service public class UserServiceimpl implements UserService { @Autowired private UserRepository userRepository; @Override public List findAll() { return userRepository.findAll(); } }
 package com.south.service; import com.south.entity.User; import java.util.List; public interface UserService { public List findAll(); }

11.Repository

   

12.测试所用的jsp

 <%@page contentType="text/html;charset=UTF-8" %><%@page isELIgnored="false" %><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  Title  ${user.id}-${user.username}-${user.password}-${user.age}

最后放出根目录的图片,方便大家学习参考

以上就是Java教程手把手教你搭建企业级工程SSM框架的详细内容,更多关于Java教程搭建企业级SSM框架的资料请关注0133技术站其它相关文章!

以上就是Java开发之手把手教你搭建企业级工程SSM框架的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java