当前位置:网站首页>_ Mold_ Board_

_ Mold_ Board_

2022-04-23 16:50:00 Kramer_ one hundred and forty-nine

front end

AJAX request

$ajax({
	url : "",
	data : {


	},
	type : "",
	dataType : "",
	success : function(){

	}
})

url Don't to "/" start , With webapp At the beginning of the directory under , such as workbench/xxx/xxx/xxx.jsp

web.xml 4.0

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
</web-app>

jsp Page character encoding 、 Take the path

Top write

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>

stay head The label says <base href="<%=basePath%>">
take html Change to jsp after , Delete... From all paths ../

added base After tag , All relative paths fail , Absolute path must be used .( from webapp Next time )

Back end

MySQL link URL

sentence jdbc:mysql://localhost:3306/ssm?serverTimezone=UTC

JDK Compiled version

pom In file

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

pom Resource file

    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>

MyBatis Reverse engineering files

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    <!-- Specifies the connection to the database JDBC  The location of the driver package , Specify the full path to your computer : Modify according to the specific situation -->
    <classPathEntry location="D:\PROGRAM\MySQL\mysql-connector-java-8.0.20\mysql-connector-java-8.0.20.jar"/>
    <!-- To configure table Table information content body ,targetRuntime  Specify the use of MyBatis3 Version of -->
    <context id="tables" targetRuntime="MyBatis3">
        <!-- Suppress generation of comments , Because the generated annotations are all in English , You can't let it generate -->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!-- Configure the database connection information : Modify according to the specific situation -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC" userId="root" password="123456">
            <property name="nullCatalogMeansCurrent" value="true"/>

        </jdbcConnection>


        <!-- Generate model class ,targetPackage Appoint model Class ,targetProject Specify the generated model Under which project : Modify according to the specific situation -->
        <javaModelGenerator targetPackage="com.daihan.springboot.model" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="false"/>
        </javaModelGenerator>
        <!-- Generate MyBatis Of Mapper.xml file ,targetPackage Appoint mapper.xml The package name of the file ,targetProject Specify the generated mapper.xml Under which project -->
        <sqlMapGenerator targetPackage="com.daihan.springboot.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        <!-- Generate MyBatis Of Mapper Interface class file ,targetPackage Appoint Mapper The package name of the interface class ,targetProject Specify the generated Mapper Which project is the interface placed under -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.daihan.springboot.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>


        <!-- Database table name and corresponding Java Model class name -->
        <table tableName="t_Student" domainObjectName="Student" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
    </context>
</generatorConfiguration>

hold jar Package import maven in

stay jar Execute in the directory where the package is located cmd
Enter the command

mvn install:install-file -Dfile=jar Package name .jar -DgroupId=maven Corresponding groupid -DartifactId=maven Corresponding artifactId -Dversion=4.2 Version number  -Dpackaging=jar

Mysql URL

mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE

The back end accepts and processes JSON

Accept parameters

@RequestBody Accept the request body
@RequestHeader Accept request header

// The request bodies accepted here are Data generic list, Accept... In the request header id by myId
public ResponseEntity courseDataSync(@RequestBody List<Data> data,@RequestHeader("id") String myId) {
    
	// Specifically Java sentence 
}                  

Data Class definition

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpstreamSyncCourseData {
    

    private String id;
    private String name;
    private String description;
    private String announcement = "";

	//json Medium course_start_time Corresponding Data Class courseStartTime Variable 
    @JsonProperty(value = "course_start_time")
    private Long courseStartTime;
    @JsonProperty(value = "advance_days")
    private Integer courseCreateTime;
}

Output JSON

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MyTest {
    
    public static void main(String[] args) throws JsonProcessingException {
    
        Phone phone = new Phone();
        phone.setName(" millet ");
        phone.setColor(" Red ");
        phone.setPrice(2000);

        ObjectMapper mapper = new ObjectMapper();
        String value = mapper.writeValueAsString(phone);
        System.out.println(value);
        //{"name":" millet ","color":" Red ","price":2000}
    }
}

版权声明
本文为[Kramer_ one hundred and forty-nine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231359460394.html