SSM简单整合

依赖pom文件

    

  
4.0.0

com.zheng
ssmNoModel
1.0-SNAPSHOT
war

ssmNoModel Maven Webapp
 
http://www.example.com


UTF-8
1.8
1.8
5.0.2.RELEASE
8.0.15
3.4.5
5.0.1.RELEASE





  org.aspectj
  aspectjrt
  1.9.2



  org.aspectj
  aspectjweaver
  1.9.2



  org.springframework
  spring-aop
  ${spring.version}



  org.springframework
  spring-context
  ${spring.version}



  org.springframework
  spring-context-support
  ${spring.version}



  org.springframework
  spring-web
  ${spring.version}



  org.springframework
  spring-beans
  ${spring.version}



  org.springframework
  spring-core
  ${spring.version}



  org.springframework
  spring-test
  ${spring.version}



  org.springframework
  spring-webmvc
  ${spring.version}



  org.springframework
  spring-test
  ${spring.version}



  org.springframework
  spring-tx
  ${spring.version}



  org.springframework
  spring-jdbc
  ${spring.version}



  mysql
  mysql-connector-java
  ${mysql.version}




  javax.servlet
  javax.servlet-api
  3.1.0
  provided




  com.alibaba
  druid
  1.0.29




  javax.servlet
  javax.servlet-api
  3.1.0
  provided




  javax.servlet.jsp
  jsp-api
  2.0
  provided



  jstl
  jstl
  1.2



  org.mybatis
  mybatis
  ${mybatis.version}




  org.mybatis
  mybatis-spring
  1.3.2



  c3p0
  c3p0
  0.9.1.2
  jar
  compile





  org.springframework.security
  spring-security-web
  ${spring.security.version}



  org.springframework.security
  spring-security-config
  ${spring.security.version}



  org.springframework.security
  spring-security-core
  ${spring.security.version}




  org.springframework.security
  spring-security-taglibs
  ${spring.security.version}




  junit
  junit
  4.11

  


ssmNoModel

  
    
      maven-clean-plugin
      3.1.0
    
    
    
      maven-resources-plugin
      3.0.2
    
    
      maven-compiler-plugin
      3.8.0
    
    
      maven-surefire-plugin
      2.22.1
    
    
      maven-war-plugin
      3.2.2
    
    
      maven-install-plugin
      2.5.2
    
    
      maven-deploy-plugin
      2.8.2
    
  

  

配置文件

数据库映射文件注意其文件必须和class文件相同路径且名字必须相同



  

  

applicationContext.xml





    
    
    
    



    
    



    





    




    
        
        
        
        
        
    



    
    




springmvc.xm配置文件








    
    

    


web.xml





Archetype Created Web Application


  
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

  encoding
  UTF-8


  forceEncoding
  true



encodingFilter
/*





org.springframework.web.context.ContextLoaderListener



contextConfigLocation
classpath:applicationContext.xml




springmvc
org.springframework.web.servlet.DispatcherServlet

  contextConfigLocation
  classpath:springmvc.xml

1



springmvc
/





页面视图

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


Title


test


list.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


Title

  
  
${item.name}
${item.pric}
${item.pice}
${item.detail}

代码

持久层代码

public interface IDao {
     public Item findById(Integer i);
}

domain代码

public class Item {
private Integer id;
private String name;
private Double pric;
private String pice;
private Date createtime;
private String detail;

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Double getPric() {
    return pric;
}

public void setPric(Double pric) {
    this.pric = pric;
}

public String getPice() {
    return pice;
}

public void setPice(String pice) {
    this.pice = pice;
}

public Date getCreatetime() {
    return createtime;
}

public void setCreatetime(Date createtime) {
    this.createtime = createtime;
}

public String getDetail() {
    return detail;
}

public void setDetail(String detail) {
    this.detail = detail;
}

@Override
public String toString() {
    return "Item{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", pric=" + pric +
            ", pice='" + pice + '\'' +
            ", createtime=" + createtime +
            ", detail='" + detail + '\'' +
            '}';
}

}

业务层代码

@Service
public class ItemServiceImp implements ItemService {
@Autowired
private IDao iDao;

@Override
public Item findById(Integer i) {
    return iDao.findById(i);
}
}

控制器代码

@Controller
@RequestMapping("/items")
public class ItemControllers {

@Autowired
private ItemService itemService;


@RequestMapping("/findById")
public ModelAndView  findById(ModelAndView model){
    Item item = itemService.findById(1);
    String s = item.toString();
    model.addObject("item",item);
    model.setViewName("list");
    return model;

}

}

测试代码

public class Testclass {

@Test
public void findById()
{
    ApplicationContext ac = new       ClassPathXmlApplicationContext("applicationContext.xml");
//        IDao iDao = ac.getBean(IDao.class);
//        Item i = iDao.findById(1);
    ItemService service = ac.getBean(ItemService.class);
    Item i = service.findById(1);
    System.out.println(i);
}

}

问题sql版本问题,以及https://www.jianshu.com/p/030aa1277e3f

你可能感兴趣的:(SSM简单整合)