java中的接口是类吗
327
2022-11-22
基于maven搭建一个ssm的web项目的详细图文教程
1:使用idea建立一个web项目
2:引入pom依赖
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <version>3.1.0
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<version>3.1.0
3: 在src/main新建java和resource文件夹
1:将java文件夹marked directory as source root
2:将resource新建resource文件夹
4:在resource新建以下文件
5:spring配置文件applicationContent.xml配置
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xmlns:tx="http://springframework.org/schema/tx" xmlns:aop="http://springframework.org/schema/aop" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.3.xsd http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.3.xsd http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx-4.3.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context"
xmlns:tx="http://springframework.org/schema/tx" xmlns:aop="http://springframework.org/schema/aop"
xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd
http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.3.xsd
http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-4.3.xsd
http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx-4.3.xsd">
6:springMVC配置文件
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.3.xsd"> class="org.springframework.http.converter.StringHttpMessageConverter">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context"
xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd
http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-4.3.xsd">
class="org.springframework.http.converter.StringHttpMessageConverter">
class="org.springframework.http.converter.StringHttpMessageConverter">
7:jdbc.properties配置文件
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
jdbc.username=axin
jdbc.password=19950925
8:log4j.properties配置文件
log4j.rootLogger=DEBUG,stdout
log4j.logger.com.mchange.v2 = INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n
9:logback.xml配置文件
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.RollingFileAppender"> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.RollingFileAppender">
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
10 mappera.xml配置
SELECT '1' id, 'guoxin' name from dual
配置webapp下的文件 web.xml的配置
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
hello.jsp
java案例
DemoController.java
package com.ssm.demo.controller;
import com.ssm.demo.entity.User;
import com.ssm.demo.service.DemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class DemoController {
@Resource
private DemoService demoService;
private static final Logger LOG = LoggerFactory.getLogger(DemoController.class);
@RequestMapping("/hello")
public User hello() {
LOG.info("输出日志");
User test = demoService.test();
return test;
}
}
User.java
package com.ssm.demo.entity;
import lombok.*;
@ToString
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class User {
private int id;
private String name;
}
DemoService.java
package com.ssm.demo.service;
import com.ssm.demo.entity.User;
public interface DemoService {
User test();
}
DemoServiceImpl.java
package com.ssm.demo.service.impl;
import com.ssm.demo.entity.User;
import com.ssm.demo.service.DemoService;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("demoService")
public class DemoServiceImpl implements DemoService {
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
// mybatis sql模板的命名空间
private static final String NAMESPACE = "com.frame.mapper.DemoMapper";
@Override
public User test() {
return (User)sqlSessionTemplate.selectOne(NAMESPACE + ".getTest");
}
}
配置tomcat
选择tomcat Server
配置好项目的application context,即访问路径
启动tomcat
访问
输入:http://localhost:8080/ssm/
输入:http://localhost:8080/ssm/hello
总结
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~