c语言sscanf函数的用法是什么
280
2022-12-08
Java开发之手把手教你搭建企业级工程SSM框架
目录1.在IDEA界面中创建MavenWeb工程2.在pom.xml中添加如下相关依赖3.web.xml 配置 Spring MVC、Spring4.分别在main目录下创建resource包5.在spring.xml中连接数据库6.springmvc.xml中配置驱动和前后缀表达式7.配置打印sql语句和指定实体类,让idea搜索需要的javaBean8.创建与数据库相对应的实体类9.Handler10.Service及其接口11.Repository12.测试所用的jsp
关于Spring + Spring MVC + MyBatis的搭建
1.在IDEA界面中创建MavenWeb工程
选中下图maven-archetype-webapp
2.在pom.xml中添加如下相关依赖
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> </plugin> jxfwvgxN
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
</plugin>
jxfwvgxN
3.web.xml 配置 Spring MVC、Spring
设置字符编码过滤器、加载静态资源。
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
4.分别在main目录下创建resource包
并创建spring,springmvc,mybatis.xml文件
5.在spring.xml中连接数据库
将user和password改成自己的数据库用户名和密码,并将3306/后面改成连接数据库的包名,紧接着配置SqlSessionFactory,扫描Mapper接口,事务管理等。
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xmlns:aop="http://springframework.org/schema/aop" xmlns:tx="http://springframework.org/schema/tx" xsi:schemaLocation="http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.3.xsd http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-3.2.xsd http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx-4.3.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.3.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:aop="http://springframework.org/schema/aop"
xmlns:tx="http://springframework.org/schema/tx"
xsi:schemaLocation="http://springframework.org/schema/aop
http://springframework.org/schema/aop/spring-aop-4.3.xsd
http://springframework.org/schema/beans
http://springframework.org/schema/beans/spring-beans-3.2.xsd
http://springframework.org/schema/tx
http://springframework.org/schema/tx/spring-tx-4.3.xsd
http://springframework.org/schema/context
http://springframework.org/schema/context/spring-context-4.3.xsd">
6.springmvc.xml中配置驱动和前后缀表达式
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xmlns:mvc="http://springframework.org/schema/mvc" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-3.0.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-3.0.xsd http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-3.2.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:mvc="http://springframework.org/schema/mvc"
xsi:schemaLocation="http://springframework.org/schema/beans
http://springframework.org/schema/beans/spring-beans-3.0.xsd
http://springframework.org/schema/context
http://springframework.org/schema/context/spring-context-3.0.xsd
http://springframework.org/schema/mvc
http://springframework.org/schema/mvc/spring-mvc-3.2.xsd">
7.配置打印sql语句和指定实体类,让idea搜索需要的javaBean
"http://mybatis.org/dtd/mybatis-3-config.dtd">
http://
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
return userRepository.findAll();
}
}
package com.south.service;
import com.south.entity.User;
import java.util.List;
public interface UserService {
public List
}
11.Repository
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select * from t_user
12.测试所用的jsp
<%@page contentType="text/html;charset=UTF-8" %>
<%@page isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
${user.id}-${user.username}-${user.password}-${user.age}
最后放出根目录的图片,方便大家学习参考
以上就是Java教程手把手教你搭建企业级工程SSM框架的详细内容,更多关于Java教程搭建企业级SSM框架的资料请关注我们其它相关文章!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~